问题
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
回答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 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.
来源:https://stackoverflow.com/questions/57460321/generating-classes-from-wsdl-in-java-11