如何从build.gradle文件运行WSDLToJava?

时间:2017-11-04 13:53:54

标签: java jaxb cxf wsdl2java

我成功地从命令行运行WSDLToJava类,从WSDL生成JaxB类。

   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

如何从“build.gradle”文件运行相同的命令行?我是Gradle的新手。

提前感谢您的帮助。 皮特

1 个答案:

答案 0 :(得分:0)

虽然有一些Gradle插件可以实现这一点,但我认为直接通过JavaExec任务进行调用也很容易。将以下内容添加到您的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.csf.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]
//    }
//}

运行gradlew wsdl2java

执行任务