Home > Java > javaTutorial > body text

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

DDD
Release: 2024-11-06 15:20:03
Original
380 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template