Search code examples
intellij-ideajaxbjava-15

JAXB on JDK15: which jars are needed?


I work in intelliJIDEA with JDK15 without any Gradle, Maven or else.
Yes, we all know that JAXB is removed from JDK since JDK11.
So I tried to simply add some libs to the project as jar files:

    jaxb-runtime-3.0.0
    jaxb-impl-3.0.0
    jaxb-core-3.0.0
    jaxb-api-2.4.0-b180830.03592
    xmlbeans-2.6.02
    activation-1.0.22

Still, all I get is:

    javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.

on this line:

    jaxbContext = JAXBContext.newInstance(Hamster.class);

Any clue?


Solution

  • You have a mix-up of incompatible library versions: neither jaxb-impl-3.0.0.jar nor jaxb-runtime-3.0.0.jar is an implementation of JAXB API 2.4.0. There has been a breaking change between Java EE 8 specifications (like JAXB 2.4.0) and Jakarta EE 9 specifications (like JAXB 3.0): basically the package namespace javax. has been replaced with jakarta.*.

    Therefore in order to use JAXB 3.0 you need:

    • either jaxb-impl-3.0.0.jar from com.sun.xml.bind and its dependencies or jaxb-runtime-3.0.0.jar from org.glassfish.jaxb and its dependencies. The former has less dependencies (many minor dependencies were condensed into jaxb-core-3.0.0.jar; you shouldn't mistake it with the org.glassfish.jaxb artifact of the same name),
    • to replace all javax.xml.bind with jakarta.xml.bind in your code.