What are the JAXB Jar files to be used with Java 17 project
Asked Answered
W

7

14

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.

Wizardry answered 5/4, 2023 at 6:58 Comment(1)
Well, you should be able to get the relevant information yourself via a quick google search. If you want to go for Jakarta EE (formerly Java EE) you'd get Jaxb as well so I'd use the respective versions. For Jakarta EE compatibility, could could refer here (result of a quick search): en.wikipedia.org/wiki/Jakarta_EESorrow
C
9

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>
Communion answered 5/4, 2023 at 7:29 Comment(4)
Thanks for your response. What are the other Jar files that is needed to add like jaxb-impl, jaxb-core, etc. and what should their version to work with JDK 17.Wizardry
@AnjitSingha, it worked for you ?. This is Not working for me , can you please help me on this ?Achelous
The question asked about Java 17, not Java 8. This answer isn't helpful.Decedent
I've never ever mentioned that is a Java 8 based solution. I wrote a JavaEE 8 and a JakartaEE solution. Java 8 is totally different than JavaEE 8Communion
C
5

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>
Costotomy answered 20/11, 2023 at 7:40 Comment(2)
This work for me in spring-boot 3 and JAXBPresser
Depending on the locally existing code, different combinations of the given versions work for different people. I have seen an example where this exact set of dependencies worked, but only after downgrading impl and runtime to 2.3.1, so that all three dependencies had the same version.Rothko
M
2

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>
Mcilwain answered 5/4, 2023 at 7:27 Comment(0)
D
2

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>
Decedent answered 15/11, 2023 at 15:19 Comment(0)
C
1

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.

Comras answered 6/4, 2023 at 12:56 Comment(0)
H
0

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.

Hartz answered 29/6, 2024 at 0:6 Comment(0)
I
0

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>
Internee answered 1/7, 2024 at 4:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.