3

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?
scrutari
  • 1,378
  • 2
  • 17
  • 33
Ivan G.
  • 700
  • 8
  • 19
  • Current workaround looks like this: `find . -name '*.java' -print0 | xargs -0 perl -pi -e 's|\Qjavax.xml.bind\E|jakarta.xml.bind|g'`, ran with the maven exec plugin. Not great – Ivan G. Jul 17 '20 at 21:47

1 Answers1

0

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>
scrutari
  • 1,378
  • 2
  • 17
  • 33