简体   繁体   English

在 java 11 中从 wsdl 生成类

[英]generating classes from wsdl in java 11

How to generate classes from WSDL in java 11 using gradle 5?如何使用 gradle 5 从 Java 11 中的 WSDL 生成类?

I was using wsimport seeber plugin, but it looks like it doesn't work in java 11我正在使用 wsimport seeber 插件,但它看起来在 java 11 中不起作用

dependencies {
            classpath "gradle.plugin.me.seeber.gradle:gradle-wsimport-plugin:1.1.1"
}

In Intelij Idea I'm getting:在 Intelij Idea 我得到:

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

    Exception thrown while executing model rule: WsimportPlugin.PluginRules#createWsdlSourceSets(ModelMap, FileOperations) > create(wsdlMain) > create(wsdl) Could not create LanguageSourceSet of type WsdlSourceSet执行模型规则时抛出异常:WsimportPlugin.PluginRules#createWsdlSourceSets(ModelMap, FileOperations) > create(wsdlMain) > create(wsdl) 无法创建 WsdlSourceSet 类型的 LanguageSourceSet

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 . Wsinport 和 wsgen 工具已从 Java 11- JEP 320中删除,但它们可以在Metro JAX-WS 中找到,后者现在是EE4J iniciative 的一部分。

Command line tool like wsimport was nothing else but wrapper around calling Java class com.sun.tools.ws.WsImport .wsimport这样的命令行工具只不过是调用 Java 类com.sun.tools.ws.WsImport包装器。 This class is included in Metro JAX-WS (available in maven artifacts jaxws-rt or jaxws-tools or others)此类包含在 Metro JAX-WS 中(可在 Maven 工件jaxws-rtjaxws-tools或其他工具中使用

Classes can be generated directly from Java :类可以直接从 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 :或者可以通过 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'
}

Tested in Java 13 and Gradle 6.在 Java 13 和 Gradle 6 中测试。

The best part is, there are no extra plugins or fancy dependencies, except for 'original' one.最好的部分是,除了“原始”插件之外,没有额外的插件或花哨的依赖项。

You can try using a new plugin for Gradle wsdl2java .您可以尝试为 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']
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM