分享我的迁移经验
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
到
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
我们使用原始插件从 WSDL 文件生成源。 有人请求使用 Java 11 而不是 Java 8,更改后原始插件生成了警告。
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/D:/mr/org/glassfish/jaxb/jaxb-runtime/2.3.0/jaxb-runtime-2.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
由于这个问题仍然被报告为 maven-jaxb2-plugin 中的错误,并且自 2018 年以来该插件没有更新,因此我们决定移动 mojo 插件。
以下是原始执行的样子:
<execution>
<id>uniqa</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<schemaDirectory>src/main/resources/brokeredinsurance/uniqa/out</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<generatePackage>at.porschebank.brokeredinsurance.uniqa.out</generatePackage>
<generateDirectory>
${project.build.directory}/generated-sources/brokeredinsurance/uniqa/out
</generateDirectory>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.5</version>
</plugin>
</plugins>
<bindingDirectory>src/main/resources</bindingDirectory>
</configuration>
</execution>
迁移新插件后
<execution>
<id>uniqa</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/brokeredinsurance/uniqa/out</source>
</sources>
<packageName>at.porschebank.brokeredinsurance.uniqa.out</packageName>
<outputDirectory>
${project.build.directory}/generated-sources/brokeredinsurance/uniqa/out
</outputDirectory>
<xjbSources>
<xjbSource>src/main/resources/jaxb-bindings.xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
在新插件中,我们有不同的标签,但从上面的代码中映射它们是非常明显的。
由于新插件使用不同,我必须在新执行中更改
goal
。所以它从generate
变成了xjc
。请参阅此处的插件文档 什么是 JAXB2 Maven 插件? 以及有关 xjc 的信息 jaxb2:testXjc<schemaInclude>
标签,因为我们的目录仅包含 wsdl 文件。此外,我们删除了额外的插件定义,因为新插件不需要它。总结
迁移到新插件非常容易,但需要一些时间来弄清楚标签的映射。
然而,我在迁移过程中遇到了一个问题,因为我们的所有内容都在
src/main/resources
文件夹中,其中根目录中有 xjb 文件。<xjbSource>
也可以包含目录,这是有效的,但是当我仅定义文件夹时,出现以下错误:
org.xml.sax.SAXParseException: not an external binding file. The root element must be {http://java.sun.com/xml/ns/jaxb}bindings but it is {http://schemas.xmlsoap.org/wsdl/}definitions
这是显而易见的,因为我们在同一文件夹(子文件夹中)也有 wsdl 文件,并且插件在初始化期间遍历整个内容,并首先找到 wsdl 文件。
因此,就我而言,解决方案是定义文件的路径。之后它立即生成类。
我知道这个问题有点老了,但原始插件今年已更新,有很多变化:
如果您有兴趣,可以阅读并遵循 迁移指南,因为我们做了一些
groupId
移动(所有内容现在都在 org.jvnet.jaxb
groupId 下发布)并做了一些 artifactId
重命名。
对于您的配置,如果仍在 JAXB2 下,您可以移至
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>2.0.9</version>
并在配置部分中,将 jaxb2-basics 引用更改为以下内容
<execution>
<configuration>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>2.0.9</version>
</plugin>
</plugins>