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

问题描述 投票:1回答:2

在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>

是否有一种简单的方法来安装wsimport或使用另一个插件捆绑特定于体系结构的wsimport来继续生成WSDL类?

java maven wsdl jax-ws java-11
2个回答
2
投票

新版本的jaxws-maven-pluginlink)可以使用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>

另一个插件也可以是Apache CXF的cxf-codegen-plugin(link


2
投票

发现这个 - https://github.com/mojohaus/jaxws-maven-plugin/issues/54#issuecomment-440597801我使用了与org.jvnet.jax-ws-commons jaxws-maven-plugin相同的配置。认为它与org.codehaus.mojo相同,但不是100%肯定。

使用JDK 11进行测试。生成所有XSD元素,端口和服务。您还需要向pom添加一些依赖项。最低:

        <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>org.glassfish.main.javaee-api</groupId>
            <artifactId>javax.jws</artifactId>
            <version>3.1.2.2</version>
        </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.