5

I am trying to run "mvn clean install" command, but I get the following error:

java:[42,22] package javax.xml.bind does not exist

Do you have any idea why?

1
  • The question doesn't match the description. "javax.xml.bind" and "javax.xml.bind.annotation" are different packages, and the answers are not interchangeable. Commented Jul 9, 2023 at 9:37

3 Answers 3

8

Try adding

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

into your pom.xml file

3
  • 1
    and after adding should I directly retry running the mvn clean install command?
    – Ana
    Commented Aug 23, 2021 at 12:30
  • Sure. Possibly you will have to add more dependencies and some more setting. You did not present your pom.xml and other essential settings
    – Prophet
    Commented Aug 23, 2021 at 13:13
  • and I had to do this as well otherwise my test was failing mvn clean install -DskipTests... I'm not a java developer so I don't know if skipping these tests were a good idea. Commented Apr 10, 2022 at 19:46
4

The library javax.xml.bind has been removed from Java 11 release.
Release Notes
For fixing this you have add those dependencies explicitly in your POM file or add it to your classpath accordingly.

<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-core</artifactId>
  <version>2.3.0.1</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.3.1</version>
</dependency>

After adding it to your POM you can build the maven project. First time you can skip tests.

mvn clean install -DskipTests
0

Download jaxb API jar file, and add it as an external jar to the Java build path.

1
  • 5
    That's the reason why Maven exist to prevent such things.
    – khmarbaise
    Commented Aug 23, 2021 at 13:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.