I am in the middle of upgrading my project from Java 8 to Java 17. My project use JAXB related JAR files. However, I am getting a lot of error while compiling the project and most of them are related to JAXB. Can anyone please help me with JAXB related JAR files and their version I should be using in my project for Java 17? Also, please suggest the compatible JAVA EE release I should be using.
In Java 8 and earlier, JAXB was integrated within JVM itself, but this was changed in Java 9. Because of the modularization of the JVM (Project Jigsaw), JAXB and some others were removed from JDK. This doesn't mean JAXB is no longer supported, just that it´s another dependency that needs to be on the classpath.
Due to JavaEE / Jakarta EE having breaking changes regarding namespace, the right dependency coordinates depends on what kind of enterprise specification is used.
In case of JavaEE 8 - the javax.*
namespace - the correct dependency is:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
and the dependency compilant with JakartaEE - the jakarta.*
namespace - is:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
When i added the following dependencies, worked for Spring boot 3.1.4 and Java 17 version.
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.0</version>
</dependency>
Begin to migrate from Java 8 to Java 11 first.
Then read for example articles like Removal of Java EE and CORBA Modules in Java 11 (https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-561005C1-12BB-455C-AD41-00455CAD23A6) : JAXB and JAX-WS are no longer bundled with JDK.
Or this one : https://learn.microsoft.com/java/openjdk/transition-from-java-8-to-java-11
So you will need to add JAX-B for example.
With Maven:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
However an implementation may be also necessary.
Like :
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.8</version>
</dependency>
I'm running Java 17.0.5 2022-10-18 LTS and this worked for me:
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.7</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.8</version>
</dependency>
</dependencies>
Here are the JAXB dependencies that I use in hisrc-higherjaxb-sample-jaxbplugins (zip), a JAXB 4.x sample project built using JDK 17. Focus on the dependencies below hisrc-basicjaxb-runtime, in this dependency tree, for the answer to your question.
org.patrodyne.jvnet:hisrc-higherjaxb-sample-jaxbplugins:jar:2.1.0
+- org.patrodyne.jvnet:hisrc-basicjaxb-runtime:jar:2.1.0:compile
| +- jakarta.activation:jakarta.activation-api:jar:2.1.1:compile
| +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:compile
| +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.2:compile
| | \- org.glassfish.jaxb:jaxb-core:jar:4.0.2:compile
| | +- org.eclipse.angus:angus-activation:jar:2.0.0:runtime
| | +- org.glassfish.jaxb:txw2:jar:4.0.2:compile
| | \- com.sun.istack:istack-commons-runtime:jar:4.1.1:compile
| +- commons-io:commons-io:jar:2.11.0:compile
| \- org.slf4j:slf4j-api:jar:2.0.6:compile
\- org.patrodyne.jvnet:hisrc-basicjaxb-testing:jar:2.1.0:test
+- org.junit.jupiter:junit-jupiter-api:jar:5.9.2:test
| +- org.opentest4j:opentest4j:jar:1.2.0:test
| +- org.junit.platform:junit-platform-commons:jar:1.9.2:test
| \- org.apiguardian:apiguardian-api:jar:1.1.2:test
\- xmlunit:xmlunit:jar:1.6:test
Note: The 4.x release of the JAXB API, RI and ZIP uses the latest JAXB Schema Binding 3.0 Specification for Jakarta EE 10.
Take a look at this answer.
I just solved this issue adding those dependencies AND ALSO changing imports from javax.xml.bind.*
to jakarta.xml.bind.*
and didn't need to change any of the code (moving from java 8 to java 17)
Hope this helps.
I used the following dependencies for Java 17 (while moving from Java 8) and worked for me
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.4</version>
</dependency>
© 2022 - 2025 — McMap. All rights reserved.