简体   繁体   中英

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

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM