I'm working on migrating a Java project to use Jakarta EE with Java 17, and I'm facing an issue where running mvn generate-sources
generates classes using the javax
namespace instead of the expected jakarta namespace. My project uses JAXB for XML binding, and I've updated my dependencies to use the latest Jakarta EE versions. However, the generated sources still reference javax.xml.bind annotations.
Here's a snippet of my pom.xml
:
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.3</version>
</dependency>
<!-- Other dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.15.3</version>
<configuration>
<!-- Configuration details -->
</configuration>
</plugin>
<!-- Other plugins -->
</plugins>
</build>
've made sure to clean the project (mvn clean
) before generating sources. Despite this, the output still uses javax
instead of jakarta
.
Has anyone faced a similar issue, or does anyone know what might be causing this discrepancy? Any insights or suggestions on how to ensure the generated classes use the jakarta
namespace would be greatly appreciated.
when inspecting the generated sources in the target/generated-sources directory, I noticed that the annotations are still importing from the javax.xml.bind.annotation package, as shown below:
package localhost._8080.beers;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
However, I expected these to be imported from the jakarta.xml.bind.annotation package, like so:
import jakarta.xml.bind.annotation.XmlType;
It seems like you should use 4.x version of jaxb-maven-plugin instead of maven-jaxb2-plugin. See github