自 JDK 11 起替换 wsimport

问题描述 投票:0回答:6

我目前正在开发一个需要

wsimport
的项目,但我们使用 JDK 11,我发现,自该版本以来
wsimport
已从 JDK 中删除。

我搜索了答案,并尝试添加此依赖项,但目前不起作用。

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

是否有我不知道的

wsimport
的替代品?

谢谢!

java spring wsimport
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
投票

该插件的最新版本(目前为 2.6)适用于 Java 11。

http://www.mojohaus.org/jaxws-maven-plugin/index.html


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>

1
投票

JDK 11 的 jaxws-maven-plugin 尚未更新。项目上有一个 pull request 打开,但尚未合并。

这里提出了 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>
  1. 添加此依赖项:
<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>
  1. 执行
    mvn clean generate-resources
    (或默认生命周期中的任何后续阶段)。

-4
投票

终于成功了!以防万一有人遇到同样的问题:

我想使用 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>

但解决方案是直接使用控制台运行 wsimport :

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

当然,我使用的是 JDK 11

© www.soinside.com 2019 - 2024. All rights reserved.