'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
Solution 1:[1]
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.
Solution 2:[2]
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']
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gouessej |
| Solution 2 | GROX13 |
