使用 apache CXF 从 WSDL 生成 POJO,使用 equals/hashCode 方法



在我们的项目中,我们使用 gradle 从 WSDL 文件生成 pojo 类。它看起来像这样(重要位(:

dependencies {
compile project(':util')
compile ("org.apache.cxf:cxf-rt-frontend-jaxws:$apachecxfVersion") {
exclude group: 'asm'
}
compile "org.apache.cxf:cxf-rt-transports-http:$apachecxfVersion"
compile "org.apache.cxf:cxf-rt-transports-http-jetty:$apachecxfVersion"
compile "org.apache.cxf:cxf-tools-common:$apachecxfVersion"
wsgen "org.apache.cxf:cxf-tools-wsdlto-core:$apachecxfVersion"
wsgen "org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:$apachecxfVersion"
wsgen "org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:$apachecxfVersion"
jaxb "com.sun.xml.bind:jaxb-xjc:$jaxbVersion"
jaxb "com.sun.xml.bind:jaxb-impl:$jaxbVersion"
jaxb "javax.xml.bind:jaxb-api:$jaxbVersion"
}
tasks.create(name: "gen_wsbindings") {
compileJava.dependsOn xjc
ext.genDirName = "$buildDir/gen.wsdls.src"
inputs.dir new File(srcDir)
outputs.dir new File(ext.genDirName)
doFirst {
new File(ext.genDirName).mkdirs()
}
doLast {
fileTree(dir: srcDir + "/wsdl", include: "**/*.wsdl", exclude: "xxx.wsdl").each { def wsdlFile ->
println "compiling WSDL " + wsdlFile.name
javaexec {
main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
classpath = configurations.wsgen
args '-fe', 'jaxws',
'-db', 'jaxb',
'-xjc-extension',
'-asyncMethods',
'-b', srcDir + '/jaxb/jaxws-binding.xml',
'-b', srcDir + '/jaxb/jxb-binding.xml',
'-impl', '-server', '-client',
'-validate',
'-autoNameResolution',
'-d', ext.genDirName,
'-wsdlLocation', 'classpath:wsdl/' + wsdlFile.name,
wsdlFile
}
}
}
}

我试图将'-xjc-XhashCode', '-xjc-Xequals'插入到wsdlToJava进程的args中,但是我收到此错误消息:WSDLToJava Error: XJC reported 'BadCommandLineException' for -xjc argument:-extension -extension -XhashCode

我需要添加一些依赖项吗? 谢谢

归功于@Vadim对这个答案的评论,但这里是代码(我将其用于 CXF Web 服务客户端生成(:

<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>1.11.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<defaultOptions>
<bindingFile>${basedir}/src/main/resources/wsdl/binding.xml</bindingFile>
<autoNameResolution>true</autoNameResolution>
<packagenames>
<packagename>generated.ws</packagename>
</packagenames>
<extraargs>
<extraarg>-bareMethods</extraarg>
<extraarg>-xjc-Xts</extraarg>
<extraarg>-xjc-Xequals</extraarg>
<extraarg>-xjc-XhashCode</extraarg>
</extraargs>
</defaultOptions>
<includes>
<include>*.wsdl</include>
</includes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.cxf.xjcplugins</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>${cxf-xjc.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>${jaxb2-basics.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

最新更新