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

问题描述 投票:1回答:1

在我们的项目中,我们使用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

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

java gradle xjc wsdl2java
1个回答
0
投票

感谢@ 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>
© www.soinside.com 2019 - 2024. All rights reserved.