hibernate.org Bundle "import package" links to a wrong package javax.transaction in rt.jar instead of the jboss-transaction.jar
Asked Answered
M

1

8

tl;dr:

  • Why is our export package directive not taken into account, even though we are importing the javax.transaction package in our hibernate.org bundle with a version directive which is only provided by our custom javax.transaction-bundle?
  • Is there some tooling in maven/eclipse/osgi to help understand the resolving of dependencies/packages?
  • We are using Eclipse4, jdk1.8
  • When debugging the problem it becomes clear, that the javax.transaction is only provided by the SystemBundleLoader instead of the BundleLoader of our custom javax.transaction-Bundle.

long version: We are currently trying to create OSGi bundles from all our 3rd party libraries by basically using the bnd tools to repackage them. When (re)-packaging hibernate.org (5.3.7) we are facing a problem (java.lang.NoClassDefFoundError: javax/transaction/SystemException) with the import package directive of the hibernate.org library.

  • the hibernate.org library imports a package called javax.transaction
  • this package is being provided by the jboss variant of the javax.transaction and we re-package this library in a artifact called "javax.transaction" and of course export the desired package.
  • the java runtime (rt.jar, jdk 1.8.0_221) provides the same package called "javax.transaction" but with fewer classes

In our maven build we are running into a java.lang.NoClassDefFoundError when running the surefire plugin to execute our plug-in tests.

The partly reduced stacktrace from the Jenkins console log looks like this (indicating that the activation of a bundle using hibernate failed):

!ENTRY org.eclipse.osgi 4 0 2020-01-30 11:39:27.329!MESSAGE An error occurred while automatically activating bundle some.company.bundle (51).
!STACK 0
org.osgi.framework.BundleException: Exception in some.other.company.bundle.Activator.start() of bundle some.other.company.bundle
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:803)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:732)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1005)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:357)
    at org.eclipse.osgi.container.Module.doStart(Module.java:588)
    at org.eclipse.osgi.container.Module.start(Module.java:456)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:471)
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117)
    at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:557)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:331)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:39)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:469)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:414)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:153)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at  at some.other.company.bundle.AConstructorOfClassUsingHibernateStuff
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at some.other.company.bundle...
    at some.other.company.bundle...
    at some.other.company.bundle...
    at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:782)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:775)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:732)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1005)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:357)
    at org.eclipse.osgi.container.Module.doStart(Module.java:588)
    at org.eclipse.osgi.container.Module.start(Module.java:456)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:431)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:450)
    at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.getBundleClassLoader(OsgiSurefireBooter.java:179)
    at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.createCombinedClassLoader(OsgiSurefireBooter.java:117)
    at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:110)
    at org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:21)

Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.jboss.logging.Logger$1.run(Logger.java:2554)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28)
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24)
at org.hibernate.type.spi.TypeConfiguration.<clinit>(TypeConfiguration.java:59)

followed by the reason, why the activation failed

Caused by: java.lang.ClassNotFoundException: javax.transaction.SystemException cannot be found by org.hibernate_5.3.7.v20200129-1820
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:460)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:414)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:153)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

And yes, the class javax.transaction.SystemException does not exist in the org.hibernate_5.3.7.v20200129-1820.jar but in our/jboss' javax.transaction.jar. Therefore we put the javax.transaction.jar as an extraRequirements/requirement-entry to the tycho configuration, because transitive dependencies aren't resolved during test execution. But still, it appears the javax.transaction-package from the rt.jar is being preferred over the same package in our javax.transaction.jar.

The org.hibernate bundle has the following dependencies:

  • It exports basically all org.hibernate.* packages.
  • It imports javax.transaction(.xa), net.bytebuddy.*, org.dom4j(.io)
Mulish answered 5/2, 2020 at 6:54 Comment(3)
Could you provide a build script or how the bundle classpath is configured for org.hibernate_5.3.7.v20200129-1820.Avictor
for maven dependency mvn dependency:tree -Dverbose maven.apache.org/plugins/maven-dependency-plugin/examples/… for classloaders https://mcmap.net/q/1474094/-how-to-find-from-which-jar-class-loader-is-trying-to-load-a-specific-classBawdyhouse
@SubOptimal: I added the im-/exports of our hibernate bundle to the original question.Mulish
S
0

You have 3 questions in 1... But to provide a simple answer, you probably have >1 javax.transaction in your runtime, so get rid of the system one if you gonna provide a custom bundle for it.

You can try removing javax.transaction (and friends) from the packages in jre.properties

Sumptuary answered 14/5, 2020 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.