How can one make use of classes generated by the cxf-xjc-plugin in Java 11?

1.4k views Asked by At

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:

  • Is there an implementation of JAXB (for Java 11) using the original javax.xml.bind package?
  • Is there a way to configure cxf-xjc-plugin to use package jakarta.xml.bind for the generated class annotations?
1

There are 1 answers

0
scrutari On

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>