5

I have a Hibernate 5 project that perfectly builds and runs on Java 8. I tried to test it on JDK 9 ea build 171. Since it is a huge project and have other dependencies I had to add java.xml.bind module to the JVM configuration for tests:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20</version>
    <configuration>
        <argLine>--add-modules java.xml.bind</argLine>
    </configuration>
</plugin>

There were other issues that I could resolve but if used aggregated module java.se.ee(as recommended):

<argLine>--add-modules java.se.ee</argLine>

I got an exception :

java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at org.jboss.logging.Logger$1.run(Logger.java:2554)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)

I couldn't even understand why it happened because JTA library(with SystemException class) is in the class-path when tests were running.

Any suggestions on how to fix this?

Mani
  • 1,068
  • 3
  • 13
  • 27
Sergiy
  • 1,854
  • 4
  • 22
  • 34
  • JDK 9 is not yet stable, and builds for it are not guaranteed. In fact they had an auto-build under JDK 9 and disabled it, because the API is not ready yet and it just spammed errors in the emails. – coladict Jun 06 '17 at 09:11

2 Answers2

4

Java SE defines a small subset of JTA. It doesn't include javax.transaction.SystemException as that exception is in the Java EE version of JTA, not the Java SE subset.

When you run with --add-modules java.se.ee then it causes the modules shared between Java SE and Java EE to be resolved, this includes the the java.transaction module. Any attempt to load a type in the javax.transaction package will be loaded from the java.transaction module but since this module only has a small subset of JTA then javax.transaction.SystemException will not be found.

If you drop --add-modules java.se.ee from your command line then you'll find that javax.transaction.SystemException can be loaded, as it's on the class path. So if you only need JAXB (module java.xml.bind) then specify that module to --add-modules, not the "java.se.ee" aggregator that will cause all modules shared with Java EE to be resolved.

Alan Bateman
  • 5,283
  • 1
  • 20
  • 25
4

Though the question seems old, yet unanswered and since the GA release of JDK is completed. According to the migration guide and the java docs, since the module java.transaction which exports the package javax.transaction has been marked as @Deprecated.

You should ideally migrate your code to be using javaee/javax.transaction instead. Currently, you can do so using automatic module converted from the dependency:

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.2</version>
</dependency>

and adding to the module-info.java the following:-

requires javax.transaction.api;

Edit: Thanks to @ImpulseTheFox for verifying that the automatic module name for the jar version 1.3 above requires:-

requires java.transaction;
Naman
  • 27,789
  • 26
  • 218
  • 353
  • It says "Module not found: javax.transaction.api" for me :( I've added the dependency to the pom and I can see under "External Libraries" – Impulse The Fox Mar 28 '18 at 21:34
  • @ImpulseTheFox Can you confirm if you're using the same version of the dependency or if the Automatic module name of the jar has been changed by the lib owners? – Naman Mar 29 '18 at 01:10
  • @ImpulseTheFox Thanks for verifying that, if you could actually get to figure out the automatic module name for `1.3`, please feel free to edit the answer with your solution. – Naman Mar 29 '18 at 07:38
  • 1
    Okay, I found out the Version `1.2` does not have set the `Automatic-Module-Name` attribute in the `META-INF/MANIFEST.MF`, that's why `javax.transaction.api` works (it's the jar name). Version `1.3` on the other hand, set `Automatic-Module-Name: java.transaction`. But this is confusing to me, as `java.transaction` is deprecated and marked for removal. – Impulse The Fox Mar 29 '18 at 07:45
  • @ImpulseTheFox Agreed, that's what I last remembered from their update. Edited the answer accordingly as well – Naman Mar 29 '18 at 09:50
  • So just ignore the deprecation warning? – Impulse The Fox Mar 29 '18 at 10:34
  • @ImpulseTheFox If you read more about the deprecation and their replacements at http://openjdk.java.net/jeps/320, you would get to know that the deprecation would not be ignored since from the external library the module would not be deprecated. Its deprecated in the JDK itself. – Naman Mar 29 '18 at 10:38
  • So since I included the `javax.transaction-api` dependency I can safely ignore the deprecation warning? https://i.imgur.com/4ODPs4C.png – Impulse The Fox Mar 29 '18 at 10:51