Java 11 Package Javax.Xml.Bind Does Not Exist

Java 11 package javax.xml.bind does not exist

According to the release-notes, Java 11 removed the Java EE modules:

java.xml.bind (JAXB) - REMOVED
  • Java 8 - OK
  • Java 9 - DEPRECATED
  • Java 10 - DEPRECATED
  • Java 11 -
    REMOVED

See JEP 320 for more info.

You can fix the issue by using alternate versions of the Java EE technologies. Simply add Maven dependencies that contain the classes you need:

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>

Jakarta EE 8 update (Mar 2020)

Instead of using old JAXB modules you can fix the issue by using Jakarta XML Binding from Jakarta EE 8:

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
<scope>runtime</scope>
</dependency>

Jakarta EE 9 update (Nov 2020)

Use latest release of Jakarta XML Binding 3.0:

  • Jakarta EE 9 API jakarta.xml.bind-api
  • compatible implementation jaxb-impl
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.0</version>
<scope>runtime</scope>
</dependency>

Note: Jakarta EE 9 adopts new API package namespace jakarta.xml.bind.*, so update import statements:

javax.xml.bind -> jakarta.xml.bind

Jakarta EE 10 update (Jun 2022)

Use latest release of Jakarta XML Binding 4.0 (requires Java SE 11 or newer):

  • Jakarta EE 10 API jakarta.xml.bind-api
  • compatible implementation jaxb-impl
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.0</version>
<scope>runtime</scope>
</dependency>

Why gradle fails with package javax.xml.bind.annotation does not exist error?

I figured it out! The problem was that javac -version was wrong, it was pointing to Java 11 instead of 8 despite the fact that my java -version and ehco $JAVA_HOME were both pointing to Java 8.

I ran the gradle task with the --info option and carefully read through the output. I found that near the end it says:

Compiling with Java command line compiler 'javac'.
Starting process 'command 'javac''. Working directory: /path/to/project Command: javac @/path/to/project/build/tmp/compileJava/java-compiler-args.txt
Successfully started process 'command 'javac''
:project:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 2.035 secs.
2 actionable tasks: 2 executed

So it occurred to me to check javac -version and sure enough, I found javac 11.0.4. The reason is that the last time I used update-alternatives --config java to change my Java from 8 to 11, I forgot to do update-alternatives --config javac as well.

jdk 11 - package javax.xml.bind.annotation is declared in the unnamed module, but module javax.xml.bind.annotation does not read it

We managed to find the cause of the problem. In ide intellij I have a modules maven project and I use JLupin Platform Development Tool, so in *.iml files i dont have line:

'<'module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule = "true" type = "JAVA_MODULE" version = "4">
but i have for example:

'<'module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule = "true" type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE" version = "4">

During the development, the names of the modules were changed, then the idea asked whether to remove modules (because ide did not recognize:

type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE").
Although the chosen option was not, then ide automatically performed:

  • selecting the maven module as ignored
  • replace in the iml file from:
    '<'module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule = "true" type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE" version = "4">
    to:
    '<'module type = "JLP_NATIVE_MICROSERVICE_IMPLEMENTATION_MODULE_TYPE" version = "4">

For the above reason, the project did not correctly read the maven artifacts. After unifying the names and marking the project as not ignored, it works correctly.
The problem is not related to java packages

EDIT: its resolved as above



Related Topics



Leave a reply



Submit