1

I want to generate java class from WSDL file using spring gradle. I have already done for 1 wsdl file. But in future it might be around 200 WSDLs. Is there a beter way to generate WSDLs separately and place the java classes in different packages. say each package named with WSDL file name? Please find below my build.gradle. Is is possible to make the Ant Task common and call individually for each WSDL file separately just by passing WSDL name, package name?

// tag::wsdl[]
task genJaxb {
    ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
    ext.classesDir = "${buildDir}/classes/jaxb"
    //ext.schema = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl"
    ext.schema = "${projectDir}/src/main/resources/wsdl.test1"

    outputs.dir classesDir

    doLast() {
        project.ant {
            taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
                    classpath: configurations.jaxb.asPath
            mkdir(dir: sourcesDir)
            mkdir(dir: classesDir)

            xjc(destdir: sourcesDir, 
                    schema: schema,
                    package: "wsdl.test1") {                
                arg(value: "-wsdl")
                produces(dir: sourcesDir, includes: "**/*.java")
            }

            javac(destdir: classesDir, source: 1.6, target: 1.6, debug: true,
                    debugLevel: "lines,vars,source",
                    classpath: configurations.jaxb.asPath) {
                src(path: sourcesDir)
                include(name: "**/*.java")
                include(name: "*.java")
            }

            copy(todir: classesDir) {
                fileset(dir: sourcesDir, erroronmissingdir: false) {
                    exclude(name: "**/*.java")
                }
            }
        }
    }
}
// end::wsdl[]
arun kumar
  • 13
  • 1
  • 4

1 Answers1

0

I use wsdl2java gradle plugin to generate Java classes from multiple wsdl/xsd files. Works like a charm.

Robert-Jan
  • 180
  • 2
  • 12
  • It looks good. Thank you. Just a small request.. I could generate the java classes using this plugin but I am not able to invoke the service and read the response. I am not able to find any sample code for that.. What ever I try is not working.. Do u have any pointers or code snippet for that? – arun kumar Jul 31 '15 at 16:19
  • I'm using Spring Boot. You can use the following tutorial: https://spring.io/guides/gs/consuming-web-service/. Generate the classes (which you already did), create a web service client with configuration class. – Robert-Jan Aug 01 '15 at 17:35
  • Yeah I already did it and able connect the web service and fetch data. But I was facing "missing xmlrootelement annotation jaxb" issue and I had to implement marshalling logic as suggested [here](http://stackoverflow.com/questions/819720/no-xmlrootelement-generated-by-jaxb) – arun kumar Aug 01 '15 at 19:30
  • This is an overhead for me to do this for all the wsdl files which I am going to generate. That's why thought of trying something else. – arun kumar Aug 01 '15 at 19:37