要将 wsimport 与 xjc 一起使用,请执行以下操作:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<dependencies>
<!-- put xjc-plugins on the jaxws-maven-plugin's classpath -->
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-value-constructor</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>wsdl-gen</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${project.basedir}/src/main/resources/wsdl/</wsdlDirectory>
<bindingDirectory>${project.basedir}/src/main/resources/wsdl</bindingDirectory>
<sourceDestDir>${project.build.directory}/generated-sources/wsimport</sourceDestDir>
<extension>true</extension>
<target>2.2</target>
<verbose>true</verbose>
<!-- tell JAXB to actually use xjc-plugins -->
<args>
<arg>-B-Xequals</arg>
<arg>-B-XhashCode</arg>
<arg>-B-Xvalue-constructor</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
关键部分是 -B ,它将传递 -X... 值。
...
<args>
<arg>-B-Xequals</arg>
<arg>-B-XhashCode</arg>
<arg>-B-Xvalue-constructor</arg>
</args>
...
这会生成一个值构造函数、equals 和 hashcode 方法。equals 和 hashcode 由 jaxb2-basics 插件提供。