[英]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.使用 Apache cxf-xjc-plugin 和 Java 11 工作正常,我能够从 xsd 文件生成 Java 源。 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
. 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将 package javax.xml.bind
中的所有类移动到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
.这是一个问题,因为 cxf-xjc-plugin 生成的 Java 类是使用 package javax.xml.bind
中的注释进行注释的。
Two potential solutions exist in my mind:我脑海中存在两种可能的解决方案:
javax.xml.bind
package?是否有使用原始javax.xml.bind
package 的 JAXB(对于 Java 11)的实现?jakarta.xml.bind
for the generated class annotations?有没有办法将 cxf-xjc-plugin 配置为使用 package jakarta.xml.bind
生成 class 注释? You could use maven-antrun-plugin
to replace javax.xml.bind
with jakarta.xml.bind
in the generated files:您可以使用maven-antrun-plugin
将生成的文件中的javax.xml.bind
替换为jakarta.xml.bind
:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.