Reputation: 305
I'm writing hibernate dto-mapping osgi bundle (for glassfish), and this bundle didn't see resourses from classpath.
Manifest file:
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
Cant access files from sqljdbc4.jar, error:
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
But this library exists in exported jar file.
Also i cant access hibernate configuration file, and mapping files through class-path (class not found and resourse not found exceptions too). But next code works:
sessionFactory = new Configuration().configure(HibernateUtil.class.getClassLoader().getResource("hibernate.cfg.xml"))
.addURL(HibernateUtil.class.getClassLoader().getResource("mapping/Project.hmb.xml"))
.buildSessionFactory();
I tried to invoke
System.out.println(HibernateUtil.class.getClassLoader().getResource("hibernate.cfg.xml"));
and see this in sys out:
bundle://376.0:1/hibernate.cfg.xml
Googled for bundle classpath options, but my manifest seems ok. Need i some specific bundle classpath properties to make my bundle see classpath resourses, or what? Thanx for help!
Upvotes: 1
Views: 1330
Reputation: 5303
Hibernate can't find any resources in an other bundle than that one where the jar library is included in. Hibernate does not know the OSGI manifest files and it ignores them, so it doesn't matter if your manifest file is correct or not.
Please see my answer in this thread, the solutions which I've given there should also work for your problems.
Upvotes: 3