Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
727 views
in Technique[技术] by (71.8m points)

java - Generate classes with jaxb2-maven-plugin from 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:projectsfoosrcmainxsdservice.wsdl
[DEBUG] accept true for file c:projectsfoosrcmainxsddatatypes.xsd
[DEBUG] accept true for file c:projectsfoosrcmainxsdmore-datatypes.xsd
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...