Java 用 JDK 11 替换 wsimport
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53266846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replacement for wsimport with JDK 11
提问by Etienne Ringot
I'm currently working on a project which need wsimport but we use JDK11 and I just discovered that wsimport was removed from JDK since this version.
我目前正在开发一个需要 wsimport 的项目,但我们使用的是 JDK11,我刚刚发现自此版本以来 wsimport 已从 JDK 中删除。
I searched for answers and I tried adding this dependency but it's not working at the moment.
我搜索了答案并尝试添加此依赖项,但目前无法正常工作。
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.11</version>
</dependency>
Is there any replacement for wsimport that I'm not aware of ?
有没有我不知道的 wsimport 替代品?
Thank you !
谢谢 !
回答by Etienne Ringot
It's works, finally! Just in case someone has the same problem :
它的工作,终于!以防万一有人遇到同样的问题:
I wanted to use maven build to generate the sources, with this pom.xml :
我想使用 maven build 生成源代码,使用这个 pom.xml :
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>my.package</packageName>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
<keep>true</keep>
<executable>${java.home}/bin/wsimport</executable>
<wsdlDirectory>src/main/resources/schemas</wsdlDirectory>
<bindingFiles>
<bindingFile>${basedir}/src/bindings/binding.xjb</bindingFile>
</bindingFiles>
<target>2.1</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
But the solution is to run wsimport directly with the console :
但解决方案是直接使用控制台运行 wsimport :
wsimport -d target/generated-sources/jaxws-wsimport/ -s target/generated-sources/jaxws-wsimport/ src/main/resources/schemas/myWSDLFile.wsdl
And of course, I'm using JDK 11
当然,我使用的是 JDK 11
回答by Christopher Shirley
I'm going to add what I've found through my research into upgrading to JDK11 in case it helps someone else.
我将添加我通过研究发现的升级到 JDK11 的内容,以防它对其他人有所帮助。
Wsimport was deprecated as a part of the JDK, but was open sourced to the Eclipse Foundation. You can download it with the following link:
Wsimport 作为 JDK 的一部分已被弃用,但已向 Eclipse 基金会开放源代码。您可以通过以下链接下载:
[https://repo1.maven.org/maven2/com/sun/xml/ws/jaxws-ri/2.3.0/jaxws-ri-2.3.0.zip][1]
[ https://repo1.maven.org/maven2/com/sun/xml/ws/jaxws-ri/2.3.0/jaxws-ri-2.3.0.zip][1]
They have changed wsimport from an executable to a bat/sh script that calls the jaxws-tools.jar file. I have not actually seen it work and always get a ClassNotFoundException: javax.activation.DataSource. I have even changed their script to include the javax.activation-api-1.2.0.jar and it still does not work. It does not matter if I attempt a build through Maven or run it command-line.
他们已将 wsimport 从可执行文件更改为调用 jaxws-tools.jar 文件的 bat/sh 脚本。我还没有真正看到它的工作,总是得到一个 ClassNotFoundException: javax.activation.DataSource。我什至更改了他们的脚本以包含 javax.activation-api-1.2.0.jar,但它仍然不起作用。我是否尝试通过 Maven 进行构建或在命令行中运行它都没有关系。
This was my plugin configuration:
这是我的插件配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>app-wsdl-exec</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<executable>${tool.wsimport}</executable>
<wsdlFiles>
<wsdlFile>${basedir}/src/main/resources/app.wsdl</wsdlFile>
</wsdlFiles>
<bindingDirectory>src/main/resources/binding</bindingDirectory>
<bindingFiles>
<bindingFile>ws-binding.xml</bindingFile>
</bindingFiles>
<packageName>com.app.ws</packageName>
<staleFile>${project.build.directory}/jaxws/stale/APP.done</staleFile>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<xnocompile>false</xnocompile>
<useJdkToolchainExecutable>false</useJdkToolchainExecutable>
<keep>true</keep>
</configuration>
</execution>
</executions>
</plugin>
I also used the following so that I could develop on Windows and Jenkins could build on Linux:
我还使用了以下内容,以便我可以在 Windows 上开发,而 Jenkins 可以在 Linux 上构建:
<profiles>
<profile>
<id>win</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<tool.wsimport>${env.JAXWS_HOME}/bin/wsimport.bat</tool.wsimport>
</properties>
</profile>
<profile>
<id>nix</id>
<activation>
<os>
<family>!windows</family>
</os>
</activation>
<properties>
<tool.wsimport>${env.JAXWS_HOME}/bin/wsimport.sh</tool.wsimport>
</properties>
</profile>
</profiles>
回答by Maarten Damen
The jaxws-maven-plugin is not updated yet for JDK 11. There is a pull requestopen on the project, but it is not merged yet.
JDK 11 的 jaxws-maven-plugin 尚未更新。项目上有一个拉取请求,但尚未合并。
A temporary solution for wsimport is proposed here: https://github.com/javaee/metro-jax-ws/issues/1251#issuecomment-441424365, which probably works fine on Linux.
此处提出了 wsimport 的临时解决方案:https: //github.com/javaee/metro-jax-ws/issues/1251#issuecomment-441424365,它可能在 Linux 上运行良好。
On our project we are working with Windows environments and we fixed the wsimport according to the following example:
在我们的项目中,我们使用 Windows 环境,我们根据以下示例修复了 wsimport:
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<mkdir dir="target/generated-sources/wsimport"/>
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<exec executable="java">
<arg value="-classpath"/>
<arg value="${plugin_classpath}"/>
<arg value="com.sun.tools.ws.WsImport"/>
<arg value="-extension"/>
<arg value="-Xnocompile"/>
<arg value="-wsdllocation"/>
<arg value="/MyWSDL.wsdl"/>
<arg value="-s"/>
<arg value="target/generated-sources/wsimport"/>
<arg value="-p"/>
<arg value="com.company.client.generated"/>
<arg value="src/main/resources/MyWSDL.wsdl"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b2</version>
</dependency>
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
<!-- xml.ws module -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.1</version>
<exclusions>
<exclusion>
<!-- declare the exclusion here -->
<groupId>org.glassfish.jaxb</groupId>
<artifactId>txw2</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- javax.activation -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- wsimport -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/wsimport</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
回答by Florian Prud'homme
Today, you can use a fork as a direct replacement of org.codehaus.mojo:jaxws-maven-plugin:2.5:
今天,你可以使用 fork 来直接替换 org.codehaus.mojo:jaxws-maven-plugin:2.5:
<plugin>
<groupId>com.helger.maven</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
...
</configuration>
</plugin>
https://github.com/phax/jaxws-maven-plugin. It works well with jdk11
https://github.com/phax/jaxws-maven-plugin。它适用于 jdk11
回答by Gustavo Passini
The latest version of the plugin (2.6 by now) works with Java 11.
该插件的最新版本(现在是 2.6)适用于 Java 11。