使用WSDL中的jaxb2-maven-plugin生成类
我无法配置 jaxb2-maven-plugin
从WSDL和多个XSD文件生成Java类,这些文件都存在于同一标准目录中 src / main / xsd
。
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
.
如何使用内联XSD的jaxb2 maven插件?仅与答案正确建议使用 wsdl
插件配置中的参数,但该问题确实与内联XSD有关,而我的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.
插件目标参数列出这里。
我的插件配置为:
<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>
我正在使用 mvn -X clean jaxb2:xjc $进行测试c $ c>但插件忽略了
.wsdl
,如调试输出中所示
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
通过检查参数的Maven调试输出被传递给JAXB XJC(以及一些试验和错误)我发现我需要为插件提供2个以上的配置参数。
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.
这会停止插件扫描对于XSD文件,只需使用 .wsdl
作为源。 XSD文件作为< xsd:include schemaLocation =datatypes.xsd/>
指令包含在WSDL中,例如,这些指令在本地解析,导致所有类型从WSDL和XSD生成为Java类。
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>
没有< xmlschema> false< / xmlschema>
Maven错误:
Without the <xmlschema>false</xmlschema>
Maven errors with:
org.apache.maven.lifecycle.LifecycleExecutionException:无法执行目标org.codehaus.mojo:jaxb2 -maven-plugin:1.5:项目foo上的xjc(default-cli):无法处理模式:
/c:/projects/foo/src/main/xsd/service.wsdl
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