Reputation: 822
Using the Apache cxf-xjc-plugin with Java 11 works fine, I am able to generate Java sources from xsd files. The problem comes when attempting to make use of those Java classes with JAXB: the available implementations of JAXB for Java 11 are org.glassfish.jaxb:jaxb-runtime
or org.eclipse.persistence:org.eclipse.persistence.moxy
, which both move all classes that were in package javax.xml.bind
to jakarta.xml.bind
. This is an issue because the Java classes generated by the cxf-xjc-plugin are annotated using the annotations in package javax.xml.bind
.
Two potential solutions exist in my mind:
javax.xml.bind
package?jakarta.xml.bind
for the generated class annotations?Upvotes: 3
Views: 1858
Reputation: 476
This stand-alone Maven project download (zip) demonstrates how one can make use of classes generated by the cxf-xjc-plugin in Java 11+. It uses cxf-xjc-plugin v4.0.1 to annotate the generated Java classes with annotations from jakarta.xml.bind.annotation
. The demo includes (a) unit tests and (b) a simple application to unmarshal and marshal a sample XML file using JAXB.
Upvotes: 0
Reputation: 1628
You could use maven-antrun-plugin
to replace javax.xml.bind
with jakarta.xml.bind
in the generated files:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>fix-sources</id>
<phase>process-sources</phase>
<configuration>
<target>
<replace token="javax.xml.bind." value="jakarta.xml.bind."dir="${project.build.directory}/generated/src/main/java/path/to/sources">
<include name="**/*.java"/>
</replace>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 0