Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGI classes not visible even though the required JARs are in Bundle-classpath

We are using an Equinox based OSGI framework to run Multiple bundles.
Our bundles have dependent JARs in the Bundle-classpath and the dependent JARs are packaged along with the rest of the classes and resources in a single JAR/WAR file. But we have a problem while running multiple such Bundles.
Say,
Bundle A: Fully tested/working JAR bundle. Contains all dependent JARs in the bundle classpath and all the dependent JARs inside (under a folder named lib). Working fine when tested by deploying only this bundle

Bundle B: Similar to Bundle A. Again working when deploying separately

But when both bundles are loaded together, OSGI is not able to load classes from JARs mentioned in the bundle-classpath for the bundle that is loaded second. The bundle that is loaded first runs fine, whereas the bundle loaded second fails.

This issue currently occurs while SPRING tries to load javax.persistence.QueryHint class.

We create a Data source using our xxxx-EntityManager.xml where we create our entityManagerFactory

Dependent JARs used: (Same JARs in both the bundles)

  • Spring: 3.0.6.RELEASE JARS
  • Hibernate: 3.6.7 JARS
  • Hibernate-JPA: hibernate-jpa-2.0-api-1.0.1.Final.jar

Exception: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'targetDataSources' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [xxxx-EntityManager.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: interface javax.persistence.QueryHint is not visible from class loader at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)

Note:

  • Both the Bundles have been individually tested and working fine
  • We know that, instead of creating Bundle-classpath we can extract the thirdparty JARs outside of the bundles and use import-package. But for this current requirement, we need the third party JARs inside the parent bundle only.

Requesting OSGI experts to please help us out.

like image 782
Srivatsan Avatar asked Dec 04 '25 18:12

Srivatsan


1 Answers

I recommend to put your dependencies in individual bundles and make all packages visible to other bundles. Then add these individual bundles as dependencies (or better: import only the required packages instead of the whole bundle!). This way you can ensure that your dependencies are loaded just once. I suggest that your current configuration leads to problems in class loading, as classes are loaded twice with most probably the same serialVersionUID. And since each bundle has its own classloader, the secondary (not) loaded class won't be visible to the second bundle.

like image 158
thobens Avatar answered Dec 06 '25 15:12

thobens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!