从 WSDL 使用 jaxb2-maven-plugin 生成类 [英] Generate classes with jaxb2-maven-plugin from WSDL
问题描述
我在配置 jaxb2-maven-plugin
以从 WSDL 和多个 XSD 文件生成 Java 类时遇到问题,这些文件都存在于同一标准目录 src/main/xsd
代码>.
如何使用带有内联 XSD 的 jaxb2 maven 插件? 的相关性仅在于答案正确建议在插件配置中使用 wsdl
参数,但该问题确实与内联 XSD 相关,而我的 XSD 是外部的.
插件目标参数在此处列出.>
我的插件配置是:
<groupId>org.codehaus.mojo</groupId><artifactId>jaxb2-maven-plugin</artifactId><version>1.5</version><执行><执行><id>xjc</id><目标><目标>xjc</目标></目标></执行></执行><配置><packageName>com.x.y.model</packageName><wsdl>真</wsdl></配置></插件>
我正在使用 mvn -X clean jaxb2:xjc
进行测试,但插件忽略了调试输出中看到的 .wsdl
[DEBUG] 为文件 c:\projects\foo\src\main\xsd\service.wsdl 接受 false[DEBUG] 接受文件 c:\projects\foo\src\main\xsd\datatypes.xsd 为真[DEBUG] 接受文件 c:\projects\foo\src\main\xsd\more-datatypes.xsd 为真
通过检查传递给 JAXB XJC 的参数的 Maven 调试输出(以及一些反复试验),我发现我需要再提供 2 个插件的配置参数.
这会停止插件扫描 XSD 文件,并仅使用 .wsdl
作为源.XSD 文件作为<xsd:include schemaLocation="datatypes.xsd"/>
指令包含在 WSDL 中,例如,它们在本地解析,导致来自 WSDL 和 XSD 的所有类型生成为 Java 类.
对我有用的配置部分是:
<预><代码><配置><packageName>com.x.y.model</packageName><wsdl>真</wsdl><xmlschema>false</xmlschema><schemaFiles>service.wsdl</schemaFiles></配置>如果没有 <xmlschema>false</xmlschema>
Maven 错误:
org.apache.maven.lifecycle.LifecycleExecutionException:无法在项目 foo 上执行目标 org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc (default-cli):无法处理架构:/c:/projects/foo/src/main/xsd/service.wsdl
I am having trouble configuring the jaxb2-maven-plugin
to generate Java classes from a WSDL and multiple XSD files that all exist in the same standard directory src/main/xsd
.
how to use jaxb2 maven plugin with inline XSD? is related only in that the answers correctly suggest using the wsdl
parameter in the plugin config but that question is really concerned with inline XSDs and my XSDs are external.
The plugin goal parameters are listed here.
My plugin configuration is:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.x.y.model</packageName>
<wsdl>true</wsdl>
</configuration>
</plugin>
I am testing this with mvn -X clean jaxb2:xjc
but the plugin is ignoring the .wsdl
as seen in the debug output
[DEBUG] accept false for file c:\projects\foo\src\main\xsd\service.wsdl
[DEBUG] accept true for file c:\projects\foo\src\main\xsd\datatypes.xsd
[DEBUG] accept true for file c:\projects\foo\src\main\xsd\more-datatypes.xsd
By examining the Maven debug output of the arguments being passed to the JAXB XJC (and a bit of trial and error) I found that I needed to supply 2 more configuration parameters to the plugin.
This stops the plugin scanning for XSD files and just uses the .wsdl
as the source. The XSD files are included in the WSDL as<xsd:include schemaLocation="datatypes.xsd" />
directives, for example, which are resolved locally resulting in all types from the WSDL and XSD being generated as Java classes.
The configuration section that worked for me is:
<configuration>
<packageName>com.x.y.model</packageName>
<wsdl>true</wsdl>
<xmlschema>false</xmlschema>
<schemaFiles>service.wsdl</schemaFiles>
</configuration>
Without the <xmlschema>false</xmlschema>
Maven errors with:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc (default-cli) on project foo: Could not process schema: /c:/projects/foo/src/main/xsd/service.wsdl
这篇关于从 WSDL 使用 jaxb2-maven-plugin 生成类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!