Pete Long
Pete Long

Reputation: 107

How can I run WSDLToJava from a build.gradle file?

I am successfully able to run the WSDLToJava class from the command line to generate JaxB classes from a WSDL.

   java -Xmx128M  
        -cp "C:\cxf\apache-cxf-3.1.6\lib\cxf-manifest.jar;
             C:\java\jdk1.7.0_80\lib\tools.jar"
        -Djava.util.logging.config.file="C:\cxf\apache-cxf-3.1.6
         \etc\logging.properties" 
         org.apache.cxf.tools.wsdlto.WSDLToJava 
         -d generated -frontend jaxws21 -b C:\Project\jaxb-bindings.xml 
          C:\Project\Service.wsdl

How can I run the same command line from a "build.gradle" file? I am completely new to Gradle.

Thank you in advance for your help. Pete

Upvotes: 1

Views: 8518

Answers (1)

jstricker
jstricker

Reputation: 2180

While there are some Gradle plugins that implement this, I think it's just as easy to make the call directly via a JavaExec task. Add the following to your build.gradle:

ext.cxfVersion = "3.1.6"

configurations {
    wsdl2java
}

dependencies {
    wsdl2java("org.apache.cxf:cxf-tools-wsdlto-core:${cxfVersion}")
    wsdl2java("org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:${cxfVersion}")
    wsdl2java("org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:${cxfVersion}")
}

task wsdl2java(type: JavaExec) {
    main = "org.apache.cxf.tools.wsdlto.WSDLToJava"
    classpath = configurations.wsdl2java
    // Uncomment to add JVM arguments if necessary (e.g. for cert-based security)
    //jvmArgs = [
    //    "-Djavax.net.ssl.keyStore=${keystorePath}",
    //    "-Djavax.net.ssl.keyStorePassword=${keystorePassword}"
    //]
    args = [
        "-d", "src/gen/java",
        "example.wsdl"
        // Uncomment and remove the previous line to run for multiple WSDL files
        //"-wsdlList, "wsdls.txt"
    ]
}

// If you want to be able to debug the wsdl2java task from Eclipse, add the following
//eclipse {
//    classpath {
//        plusConfiguration += [configurations.wsdl2java]
//    }
//}

Execute the task by running gradlew wsdl2java.

Upvotes: 3

Related Questions