java 生成wsdl,在Java 11中从wsdl生成类

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值