在Java 11中从wsdl生成类 [英] generating classes from wsdl in java 11

查看:161
本文介绍了在Java 11中从wsdl生成类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Gradle 5从Java 11中的WSDL生成类?

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

我正在使用wsimport seeber插件,但是它似乎在Java 11中不起作用

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"
}

在Intelij Idea中,我得到了:

In Intelij Idea I'm getting:

  • 出了什么问题:配置项目':ReturnRedirectWorker-api'时出现问题.
  • What went wrong: A problem occurred configuring project ':ReturnRedirectWorker-api'.

执行模型规则时引发异常:WsimportPlugin.PluginRules#createWsdlSourceSets(ModelMap, FileOperations)>创建(wsdlMain)>创建(wsdl) 无法创建类型为WsdlSourceSet的LanguageSourceSet

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

推荐答案

Wsinport和wsgen工具已从Java 11中删除- Metro JAX-WS 现已成为 EE4J激励的一部分.

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.

类似于wsimport的命令行工具不过是调用Java类com.sun.tools.ws.WsImport的包装器.此类包含在Metro JAX-WS中(在Maven工件中可用 jaxws工具 或其他)

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)

可以直接从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);

或者可以通过gradle任务轻松生成:

// 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'
}

在Java 13和Gradle 6中进行了测试.

Tested in Java 13 and Gradle 6.

最好的部分是,除了原始"插件之外,没有其他插件或特殊的依赖项.

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

这篇关于在Java 11中从wsdl生成类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆