【发布时间】:2018-11-18 12:39:59
【问题描述】:
在我们的项目中,我们使用 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。
我需要添加一些依赖项吗? 谢谢
【问题讨论】:
-
我不了解 gradle,但对于 Maven jaxb/cxf 插件,它需要对
<groupId>org.jvnet.jaxb2_commons</groupId><artifactId>jaxb2-basics</artifactId>的额外依赖才能使用-XhashCode-Xequals和其他参数。同样对于cxf-codegen-plugin,向 XJC 传递额外的参数看起来像<extraarg>-xjc-Xequals</extraarg>。仍然是关于 Maven 插件,也许你可以检查一下 gradle 对应物是什么......