Home  >  Article  >  Java  >  How to Resolve the "Package javax.xml.bind Not Found" Compilation Error in Java 11?

How to Resolve the "Package javax.xml.bind Not Found" Compilation Error in Java 11?

DDD
DDDOriginal
2024-11-06 15:20:03318browse

How to Resolve the

Compilation Error: Java 11 Package javax.xml.bind Not Found

When attempting to build a Java project with Java 11, you may encounter a compilation error stating that the package javax.xml.bind does not exist. This error occurs because the Java EE modules were removed in Java 11, including JAXB (Java XML Binding).

Solution: Use Alternate Dependencies

To resolve the issue, alternate versions of the Java EE technologies must be used. Add the following Maven dependencies to your project:

<code class="xml"><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></code>

Jakarta EE 8 and Later Updates

Instead of using the old JAXB modules, you can also use Jakarta XML Binding from Jakarta EE 8 or later:

Jakarta EE 8 (March 2020)

<code class="xml"><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></code>

Jakarta EE 9 (November 2020)

<code class="xml"><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></code>

Jakarta EE 10 (June 2022)

<code class="xml"><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></code>

Note: For Jakarta EE 9 and later, update import statements to use the jakarta.xml.bind namespace instead of javax.xml.bind.

The above is the detailed content of How to Resolve the "Package javax.xml.bind Not Found" Compilation Error in Java 11?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn