问题描述
分享我的移民经历
<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
。请参阅此处的插件文档 What is the JAXB2 Maven Plugin? 和有关 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 文件。
因此,就我而言,解决方案是定义文件的路径。在此之后,它立即生成了类。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)