Reputation: 315
Current maven plugins like jaxb2-maven-plugin and maven-jaxb2-plugin generate code using the package javax.xml instead of the new jakarta.xml package of Jakarta XML Binding in Jakarta EE. It seems there's no way of configure any of them to use JAXB 3.0.
Is there any Maven plugin for JAXB 3.0?
Upvotes: 11
Views: 14132
Reputation: 11274
I am using this to make it compatible with Java17
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>4.0.8</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
<extension>true</extension>
<!-- Plugins -->
<args>
<arg>-Xfluent-api</arg>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
<version>4.0.8</version>
</plugin>
<plugin>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>2.1.8</version>
</plugin>
</plugins>
</configuration>
</plugin>
Also need add dependency for jakarta
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
<!-- JAXB Runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-runtime</artifactId>
<version>4.0.8</version>
</dependency>
Upvotes: 1
Reputation: 2981
The highsource project is active again and provides org.jvnet.jaxb:jaxb-maven-plugin
, supporting JAXB 2.3, 3.0 and 4.x.
Upvotes: 0
Reputation: 476
Yes, the source/target (release) compatibility for the projects below is at Java 11, up from Java 8. And, JDK 17 is used for the build. JAXB dependencies are at version 4.x for Jakarta EE 10.
Here hisrc-higherjaxb-sample-jaxbplugins-2.1.0-mvn-src.zip is a sample project and to learn more see HiSrc Sample JAXB Plugins.
Note: The 4.x release of the JAXB API, RI and ZIP continues to use the latest JAXB Schema Binding 3.0 Specification.
Disclaimer: I am the maintainer for the forked HiSrc projects.
Upvotes: 6
Reputation: 29
There are currently three Maven plugins that can be used to generate code from XML schemas using JAXB 3.0:
Upvotes: 1
Reputation: 190
https://github.com/evolvedbinary/jvnet-jaxb-maven-plugin is a fork of https://github.com/highsource/maven-jaxb2-plugin that adds jaxb3 support, and it's published on maven central.
Your mileage may vary with jaxb2-basics depending on the specific plugin, as it doesn't support jaxb3 at the moment.
Upvotes: 2
Reputation: 16115
jaxb2-maven-plugin
version 3.0.0 will support JAXB 3. It doesn't seem to be available yet on Maven repositories, but you can get it on github and install it locally.
Remark: the previous versions almost work (you just need to change their dependencies versions), but unfortunately AbstractJaxbMojo
preloads some JAXB classes by name and these names changed.
Upvotes: 4