gradle wsimport

只愿长相守 提交于 2021-02-08 09:13:06

问题


I'm running wsimport from my commandline to generate java classes from WSDL as below.

wsimport -J-Djavax.xml.accessExternalDTD=all 
         -J-D-Djavax.xml.accessExternalSchema=all 
         -b http://www.w3.org/2001/XMLSchema.xsd 
         -b customization.xjb 
         -s genSrc https://example.com/XYZ.asmx?wsdl

I want to create the equivalent gradle task. I shouldn't be using any random custom gradle plugins due to company restrictions. What's the best way to go about it?


回答1:


Found on web use ant task more detail on metro project site

configurations {
    jaxws
}

dependencies {
    jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}

task wsimport {
    ext.destDir = file("${projectDir}/src/main/generated")
    doLast {
        ant {
            sourceSets.main.output.classesDir.mkdirs()
            destDir.mkdirs()
            taskdef(name: 'wsimport',
                    classname: 'com.sun.tools.ws.ant.WsImport',
                    classpath: configurations.jaxws.asPath
            )
            wsimport(keep: true,
                    destdir: sourceSets.main.output.classesDir,
                    sourcedestdir: destDir,
                    extension: "true",
                    verbose: "false",
                    quiet: "false",
                    package: "com.example.client.api",
                    xnocompile: "true",
                    wsdl: 'src/main/resources/api.wsdl') {
                xjcarg(value: "-XautoNameResolution")
            }
        }
    }
}

compileJava {
    dependsOn wsimport
    source wsimport.destDir
}



回答2:


As @lunicon mention, you should use an ant task, here are some improvements since gradle has change a couple of properties.

configurations {
    jaxws
}

dependencies {
    jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}

task wsimport {
    ext.destDir = file("${projectDir}/src/main/generated")
    doLast {
        ant {
            sourceSets.main.output.classesDirs.inits()
            destDir.mkdirs()
            taskdef(name: 'wsimport',
                    classname: 'com.sun.tools.ws.ant.WsImport',
                    classpath: configurations.jaxws.asPath
            )
            wsimport(keep: true,
                    sourcedestdir: 'src/main/java',
                    package: "com.example.client.api",
                    wsdl: 'src/main/resources/api.wsdl') {
                xjcarg(value: "-XautoNameResolution")
            }
        }
    }
}

compileJava {
    dependsOn wsimport
    source wsimport.destDir
}


来源:https://stackoverflow.com/questions/49795433/gradle-wsimport

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!