Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 895
user2061066 Avatar asked Apr 07 '26 19:04

user2061066


2 Answers

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 initiative.

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.

like image 86
pufface Avatar answered Apr 11 '26 09:04

pufface


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']
}
like image 21
GROX13 Avatar answered Apr 11 '26 09:04

GROX13



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!