我正在编写hibernate dto-mapping osgi包(用于glassfish),这个包没有看到来自classpath的资源。
清单文件:
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文件中。
我也无法访问hibernate配置文件,并通过class-path映射文件(类未找到,资源也未发现异常)。但是下面的代码可以工作:
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中看到这一点:
bundle://376.0:1/hibernate.cfg.xml我在谷歌上搜索了捆绑包类路径选项,但我的清单似乎没问题。我需要一些特定的捆绑包类路径属性来让我的捆绑包看到类路径资源,还是什么?感谢您的帮助!
发布于 2012-09-21 17:34:37
除了包含jar库的捆绑包之外,Hibernate无法在其他捆绑包中找到任何资源。Hibernate不知道OSGI清单文件,它会忽略它们,所以清单文件是否正确无关紧要。
请看my answer in this thread,我在那里给出的解决方案应该也适用于你的问题。
https://stackoverflow.com/questions/12527575
复制相似问题