自JDK 11开始,wsimport的替代方案

25

我目前正在处理一个项目,需要使用wsimport,但我们使用的是JDK11,我刚刚发现从这个版本开始,wsimport已经被从JDK中移除了。

我搜索了答案,并尝试添加此依赖项,但目前还没有成功。

     <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.2.11</version>
    </dependency>

有没有我不知道的wsimport替代方案?

谢谢!


2.3.1是最新版本,请尝试使用它! - Jacob G.
3
一旦发布,使用Jakarta EE(https://github.com/eclipse-ee4j/metro-jax-ws/tree/master/jaxws-ri/jaxws-maven-plugin)中的`com.sun.xml.ws:jaxws-maven-plugin:2.3.2`。目前该插件可在OSS Sonatype暂存库(https://oss.sonatype.org/content/groups/staging/com/sun/xml/ws/jaxws-maven-plugin/2.3.2/)中获取,预计很快会发布。有关更多详细信息,请参见https://github.com/javaee/metro-jax-ws/issues/1251。 - Valentin Kovalenko
一个选择是使用Apache CXF的wsdl2java工具。 - Andy Thomas
6个回答

7
今天,您可以使用一个 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。它与jdk11兼容良好。


5

3

我将把升级到JDK11的研究成果添加进来,希望能帮助其他人。

Wsimport已作为JDK的一部分被弃用,但已开源给Eclipse基金会。您可以通过以下链接下载:

[https://repo1.maven.org/maven2/com/sun/xml/ws/jaxws-ri/2.3.0/jaxws-ri-2.3.0.zip][1]

他们已经将wsimport从可执行文件更改为调用jaxws-tools.jar文件的bat/sh脚本。我实际上没有看到它工作过,总是会出现ClassNotFoundException:javax.activation.DataSource。我甚至更改了他们的脚本以包含javax.activation-api-1.2.0.jar,但仍然不起作用。无论是通过Maven尝试构建还是在命令行中运行都无关紧要。
这是我的插件配置:
<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>

我也使用了下面的方法,这样我就可以在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>

提供的上面链接已经失效了。请您提供有效的链接! - N00b Pr0grammer
2
如果您向上一级,您将看到最新版本:https://repo1.maven.org/maven2/com/sun/xml/ws/jaxws-ri/2.3.0/,您可以在此找到它。 - Christopher Shirley

1

jaxws-maven-plugin尚未更新以适应JDK 11。该项目有拉取请求,但尚未合并。

这里提出了一个临时的wsimport解决方案:https://github.com/javaee/metro-jax-ws/issues/1251#issuecomment-441424365,在Linux上可能很好用。

在我们的项目中,我们正在使用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>

0
实际上,提供的答案都不起作用。
起作用的是这个:
  1. 添加这个插件(根据您的需求进行配置):
<build>
    <plugins>

        <!--possibly some other plugins...-->

        <plugin>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>4.0.2</version> <!--use latest version-->
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <packageName>com.your.package.path.here</packageName>
                <wsdlUrls>
                    <wsdlUrl>http://url.for.your.wsdl.com/wsdlFile?WSDL</wsdlUrl> <!--Sure enough, you change this with the real URL-->
                </wsdlUrls>
                <!--
                Alternatively you can use:
                <wsdlDirectory>path/to/your/wsdl/</wsdlDirectory>
                <wsdlFiles>
                    <wsdlFile>wsdlFileName</wsdlFile>
                </wsdlFiles>
                -->
                <sourceDestDir>${project.build.sourceDirectory}</sourceDestDir>
                <extension>true</extension>
            </configuration>
        </plugin>

        <!--possibly some other plugins...-->

    </plugins>
</build>

添加此依赖项:
<dependencies>
    
    <!--Possibly some other dependencies...-->
    
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>4.0.2</version>
    </dependency>

    <!--Possibly some other dependencies...-->
    
</dependencies>

执行mvn clean generate-resources命令(或者从默认生命周期中的任何后续阶段)。

-4

终于可以工作了!以防有人遇到同样的问题:

我想使用Maven构建来生成源代码,使用以下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>

但解决方案是直接在控制台上运行wsimport:

wsimport -d target/generated-sources/jaxws-wsimport/ -s target/generated-sources/jaxws-wsimport/ src/main/resources/schemas/myWSDLFile.wsdl

当然,我正在使用JDK 11。

9
JDK 11 没有 wsimport 工具。因此,我不确定您是如何做您所描述的事情的。 - Valentin Kovalenko

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接