简体   繁体   中英

generating classes from wsdl in java 11

How to generate classes from WSDL in java 11 using gradle 5?

I was using wsimport seeber plugin, but it looks like it doesn't work in java 11

dependencies {
            classpath "gradle.plugin.me.seeber.gradle:gradle-wsimport-plugin:1.1.1"
}

In Intelij Idea I'm getting:

  • What went wrong: A problem occurred configuring project ':ReturnRedirectWorker-api'.

    Exception thrown while executing model rule: WsimportPlugin.PluginRules#createWsdlSourceSets(ModelMap, FileOperations) > create(wsdlMain) > create(wsdl) Could not create LanguageSourceSet of type WsdlSourceSet

Wsinport and wsgen tools were removed from Java 11 - JEP 320 , but they can be found in Metro JAX-WS which is now part of EE4J iniciative .

Command line tool like wsimport was nothing else but wrapper around calling Java class com.sun.tools.ws.WsImport . This class is included in Metro JAX-WS (available in maven artifacts jaxws-rt or jaxws-tools or others)

Classes can be generated directly from Java :

// SomeClass.java
String[] args = new String[]{
    "-target", "2.1",
    "-s", "src/main/java",
    "-keep",
    "-Xnocompile",
    "-extension",
    "-encoding", "UTF-8",
    "-wsdllocation", "http://localhost/wsdl",
    "src/main/resources/META-INF/SomeService.wsdl"
};
com.sun.tools.ws.WsImport.main(args);

Or can be generated easily by gradle task :

// build.gradle
task wsImport(type: JavaExec) {
    classpath sourceSets.main.runtimeClasspath
    main = "com.sun.tools.ws.WsImport"
    args "-target", "2.1",
        "-s", "src/main/java",
        "-keep",
        "-Xnocompile",
        "-extension",
        "-encoding", "UTF-8",
        "-wsdllocation", "http://localhost/wsdl",
        "src/main/resources/META-INF/SomeService.wsdl"
}

dependencies {
    compile 'com.sun.xml.ws:jaxws-rt:2.3.2-1'
}

Tested in Java 13 and Gradle 6.

The best part is, there are no extra plugins or fancy dependencies, except for 'original' one.

You can try using a new plugin for Gradle wsdl2java . It is simple to use and configure you just need to add plugin:

plugins {
    ...
    id 'com.github.bjornvester.wsdl2java' version '1.2'
}

...

wsdl2java {
    includes = ['wsdl/test.wsdl']
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM