Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle wsimport

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?

like image 987
jana Avatar asked Aug 22 '26 22:08

jana


2 Answers

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
}
like image 141
Marco Capo Avatar answered Aug 26 '26 23:08

Marco Capo


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
}
like image 43
lunicon Avatar answered Aug 27 '26 00:08

lunicon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!