【发布时间】:2012-09-13 16:50:40
【问题描述】:
我正在编写休眠 dto-mapping osgi 包(用于 glassfish),而这个包没有看到来自类路径的资源。
清单文件:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Model
Bundle-SymbolicName: com.test.spm.model
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.test.spm.model.Activator
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.3.0"
Require-Bundle: org.hibernate.core;bundle-version="4.1.7"
Export-Package: com.test.spm.model,
com.test.spm.model.dto,
com.test.spm.model.dto.base,
com.test.spm.model.util
Bundle-ClassPath: .,
lib/sqljdbc4.jar
无法从 sqljdbc4.jar 访问文件,错误:
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
但是这个库存在于导出的 jar 文件中。
我也无法通过类路径访问休眠配置文件和映射文件(找不到类和资源也找不到异常)。但下一个代码有效:
sessionFactory = new Configuration().configure(HibernateUtil.class.getClassLoader().getResource("hibernate.cfg.xml"))
.addURL(HibernateUtil.class.getClassLoader().getResource("mapping/Project.hmb.xml"))
.buildSessionFactory();
我尝试调用
System.out.println(HibernateUtil.class.getClassLoader().getResource("hibernate.cfg.xml"));
并在 sys out 中看到这个:
bundle://376.0:1/hibernate.cfg.xml
搜索了捆绑类路径选项,但我的清单似乎没问题。 我需要一些特定的包类路径属性来让我的包看到类路径资源,还是什么?感谢您的帮助!
【问题讨论】:
标签: hibernate jakarta-ee osgi