为 JAX-WS 库正确地从 JDK-8 迁移到 JDK-11

Correctly migrating from JDK-8 to JDK-11 for JAX-WS libraries

我正在几个缺陷管理系统之间开发几个集成(作为 Maven 项目),其中一个通过 WSDL 公开服务,迫使我通过 WS 使用它们。 对于后者,我成功地开发了 JDK-8 的代码并且一切正常。

我现在正在 JDK 从 8 迁移到 11,需要更新使用 WS 的集成。我了解到在 Java 11 中删除了一些 EE 库(包括 JAX-WS)。 然后我上网冲浪以摆脱这个问题,但是经过几天的测试和依赖项的剪切和粘贴我仍然遇到同样的问题:无法实例化 WS 以与最终服务器交互(即CA SDM 14.1).

目前我有以下错误:

java.lang.NoSuchMethodException: com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getInstance()

我的 POM 文件如下所示:

<properties>
    <target.dir>target</target.dir>
    <app.version>4.0.0</app.version>
    <skipTests>true</skipTests>
    <encoding>UTF-8</encoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
    <mainClassName>unipol.alm.integrations.FireStarter</mainClassName>
    <java.version>11</java.version>
    <logback.version>1.2.3</logback.version>
    <lombok.version>1.18.20</lombok.version>
    <json.version>20210307</json.version>
    <apache.http.components.version>4.5.9</apache.http.components.version>
    <derby.version>10.14.2.0</derby.version>
    <junit.version>4.12</junit.version>
    <cucumber.version>1.2.5</cucumber.version>
    <octane.cucumber.version>12.60.48</octane.cucumber.version>
    <commons.version>2.5</commons.version>
    <json.simple.version>1.1.1</json.simple.version>
</properties>
<dependencies>
    <!-- Logging dependencies -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>${json.version}</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>${json.simple.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.8</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19.4</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>30.1.1-jre</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.14.2</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.15</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${apache.http.components.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>${apache.http.components.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>${derby.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>${derby.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.rpc</groupId>
        <artifactId>javax.xml.rpc-api</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>com.hpe.alm.octane</groupId>
        <artifactId>octane-cucumber-jvm</artifactId>
        <version>${octane.cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>${commons.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>commons-discovery</groupId>
        <artifactId>commons-discovery</artifactId>
        <version>0.4</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
        <version>1.6.2</version>
    </dependency>
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.3</version>
    </dependency>
    <dependency>
        <groupId>net.lingala.zip4j</groupId>
        <artifactId>zip4j</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.hierynomus</groupId>
        <artifactId>smbj</artifactId>
        <version>0.10.0</version>
    </dependency>
    <dependency>
        <groupId>commons-vfs</groupId>
        <artifactId>commons-vfs</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>jcifs</groupId>
        <artifactId>jcifs</artifactId>
        <version>1.3.17</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>javax.jws</groupId>
        <artifactId>jsr181-api</artifactId>
        <version>1.0-MR1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>rt</artifactId>
        <version>2.2.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.org.apache.xml.internal</groupId>
        <artifactId>resolver</artifactId>
        <version>20050927</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.stream.buffer</groupId>
        <artifactId>streambuffer</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>policy</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>3.0.2</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.1</version>
    </dependency>
</dependencies>

javax.xml.ws 开始添加的所有依赖项都是为了让 JAX-WS 在 JDK 11 上工作(在代码通过 NoClassDefFoundError 给出的连续异常之后添加)。

此外,我从缺陷管理系统公开的 WSDL 生成 Java 类,在我的 POM 中包含以下内容(这是第一次):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <goals>
                <goal>
                    wsimport
                </goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <wsdlDirectory>${project.basedir}/src/main/resources/</wsdlDirectory>
        <wsdlUrls>
            <wsdlUrl>http://defect.management.system/ServiceDefinition?wsdl</wsdlUrl>
        </wsdlUrls>
        <packageName>com.ca.unicenterserviceplus.servicedesk</packageName>
        <sourceDestDir>${project.build.directory}/generated-sources/</sourceDestDir>
    </configuration>
</plugin>

然后将生成的文件复制并粘贴到应用程序希望找到的 com.ca.unicenterserviceplus.servicedesk 中。

毕竟我的问题是:有没有办法让事情像 JDK 8 那样工作?

Oracle release notes for Java 11 中,我发现了这个:

other-libs ➜ JEP 320 Remove the Java EE and CORBA Modules

Remove the Java EE and CORBA modules from the Java SE Platform and the JDK. These modules were deprecated in Java SE 9 with the declared intent to remove them in a future release (JEP 320).

The following modules have been removed from Java SE 11 and JDK 11:

java.xml.ws (JAX-WS, plus the related technologies SAAJ and Web Services Metadata)
java.xml.bind (JAXB) 

...等等

根据我从 Oracle 了解到的内容,他们从 Java 11 中删除了 Jax-WS,但它在 OpenJDK 下仍然可用:JEP 320: Remove the Java EE and CORBA Modules。根据该页面,

This proposal assumes that developers who wish to compile or run applications on the latest JDK can find and deploy alternate versions of the Java EE technologies. The Reference Implementations (RIs) of JAX-WS and JAXB are a good starting point because they are complete replacements for the java.xml.ws and java.xml.bind modules in JDK 9. The RIs are available as Maven artifacts: (note that they must be deployed on the class path)

com.sun.xml.ws : jaxws-ri (JAX-WS, plus SAAJ and Web Services Metadata)
com.sun.xml.bind : jaxb-ri (JAXB)

The tools for JAX-WS and JAXB are also available as Maven artifacts:

wsgen and wsimport: com.sun.xml.ws : jaxws-tools, plus tool scripts
schemagen and xjc: com.sun.xml.bind : jaxb-jxc and com.sun.xml.bind : jaxb-xjc, plus tool scripts

因为你在 Java 8,你可能还需要做更多的调整 and/or 先迁移到 Java 9,但据我所知,这是你唯一的前进的道路。

总而言之,Oracle 从 Java11 中删除了 Jax-WS 和相关技术,但它们仍然可供下载和使用,这里是 link 的 Maven 存储库 (RIs) of JAX-WS and JAXB 。 詹姆斯