使用带有 Java11 的 Maven 插件从 WSDL 文件生成 JAX-WS 类

Nic*_*aux 10 java wsdl jax-ws maven java-11

在 Java 11 中,JAX-WS 已从 JDK 中删除。它可以防止wsimport在引擎盖下使用 Maven 插件轻松生成 JAX-WS 类。我正在为 Maven 插件使用以下配置org.codehaus.mojo:jaxws-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <extension>true</extension>
                <packageName>tech.myproject.service</packageName>
                <wsdlFiles>
                    <wsdlFile>${basedir}/src/main/resources/wsdl/service.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>/wsdl/service.wsdl</wsdlLocation>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法来安装 wsimport 或使用另一个插件捆绑特定架构的 wsimport 来继续生成 WSDL 类?

mad*_*uci 10

jaxws-maven-plugin链接)的新版本可以使用 Java 11 生成 Java 类,使用插件如下:

<build>
<plugins>
...
<plugin>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
      <execution>
        <id>generate-java-sources</id>
        <phase>process-sources</phase>
        <goals>
          <goal>wsimport</goal>
        </goals>
        <configuration>
          <extension>true</extension>
          <wsdlFiles>
            <wsdlFile>${project.build.directory}/generated/wsdl/MyService.wsdl</wsdlFile>
          </wsdlFiles>
          <wsdlLocation>/wsdl/MyService.wsdl</wsdlLocation>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
      </dependency>
      <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
      </dependency>
      <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.3.1</version>
      </dependency>
      <dependency>
        <groupId>javax.jws</groupId>
        <artifactId>javax.jws-api</artifactId>
        <version>1.1</version>
      </dependency>
    </dependencies>
  </plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

另一个插件也可以是来自 Apache CXF 的 cxf-codegen-plugin(链接

更新

如果你想使用较新的JakartaEE 9.0+包,你需要使用以下插件,保持相同的配置:

<build>
<plugins>
...
<plugin>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <id>generate-java-sources</id>
        <phase>process-sources</phase>
        <goals>
          <goal>wsimport</goal>
        </goals>
        <configuration>
          <extension>true</extension>
          <wsdlFiles>
            <wsdlFile>${project.build.directory}/generated/wsdl/MyService.wsdl</wsdlFile>
          </wsdlFiles>
          <wsdlLocation>/wsdl/MyService.wsdl</wsdlLocation>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>3.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>javax.transaction-api</artifactId>
            </exclusion>
        </exclusions>
      </dependency>
      <dependency>
        <groupId>jakarta.xml.ws</groupId>
        <artifactId>jakarta.xml.ws-api</artifactId>
        <version>3.0.0</version>
      </dependency>
    </dependencies>
  </plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

对于 jaxb:

<groupId>com.evolvedbinary.maven.mojohaus</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>3.0.0</version>
Run Code Online (Sandbox Code Playgroud)

  • 注意块“&lt;configuration&gt;”必须位于块“&lt;execution&gt;”之外,它必须与“&lt;plugin&gt;”处于同一级别 (2认同)