JAXB APIs are considered Java EE APIs and therefore are no longer contained in the default class path in Java SE 9. In Java 11, they are completely removed from the JDK.
Java 9 introduces the concept of modules, and by default the java.se aggregate module is available on the class path (or rather on the java.se ). As the name implies, the java.se aggregate module java.se not include the Java EE APIs that were traditionally bundled with Java 6/7/8.
Fortunately, these Java EE APIs that were provided in the JDK 6/7/8 are still in the JDK, but they simply are not in the way of the default classes. Additional Java EE APIs are provided in the following modules:
java.activation java.corba java.transaction java.xml.bind << This one contains the JAXB APIs java.xml.ws java.xml.ws.annotation
Quick and dirty solution: (JDK 9/10 only)
To make JAXB APIs available at run time, specify the following command line parameter:
--add-modules java.xml.bind
But I still need this to work with Java 8 !!!
If you try to specify --add-modules with the old JDK, it will explode because it is an unrecognized option. I offer one of two options:
- You can set any options only for Java 9+ using the
JDK_JAVA_OPTIONS environment JDK_JAVA_OPTIONS . This environment variable is automatically read by java Launcher for Java 9+. - You can add
-XX:+IgnoreUnrecognizedVMOptions to make the JVM silently ignore unrecognized parameters instead of exploding. But be careful! Any other command line arguments you use will no longer be validated by the JVM. This option works with Oracle / OpenJDK, as well as with IBM JDK (starting with JDK 8sr4)
Alternative quick fix: (JDK 9/10 only)
Please note that you can make all of the above Java EE modules available at run time by specifying the --add-modules java.se.ee The java.se.ee module is an aggregate module that includes java.se.ee and also the above Java EE API modules.
The right long-term solution: (JDK 9 and above)
All of the Java EE API modules listed above are @Deprecated(forRemoval=true) because they are planned for removal in Java 11 . So --add-module approach --add-module will no longer work in Java 11 out of the box.
What you will need to do in Java 11 and later is to include your own copy of the Java EE API in the class path or module. For example, you can add the JAX-B API as a maven dependency, like this:
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2.11</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>2.2.11</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2.11</version> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency>
For complete information on Java modularity, see JEP 261: Modular System
For Gradle or Android Studio developers: (JDK 9 and above)
Add the following dependencies to your build.gradle file:
dependencies { // JAX-B dependencies for JDK 9+ implementation "javax.xml.bind:jaxb-api:2.2.11" implementation "com.sun.xml.bind:jaxb-core:2.2.11" implementation "com.sun.xml.bind:jaxb-impl:2.2.11" implementation "javax.activation:activation:1.1.1" }