Generate JAX-WS classes from WSDL file using Maven plugin with Java11
Asked Answered
P

2

15

In Java 11, JAX-WS has been removed from the JDK. It prevents to generate easily JAX-WS classes with a Maven plugin using wsimport under the hood. I am using the following configuration for the Maven plugin 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>

Is there an easy way to install wsimport or to use another plugin bundling an architecture specific wsimport to continue generating WSDL classes?

Preeminence answered 6/11, 2018 at 13:0 Comment(1)
Might lead to some help - github.com/mojohaus/jaxws-maven-plugin/issues/…Byre
B
17

the new version of jaxws-maven-plugin (link) can generate Java classes with Java 11, using the plugin as follows:

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

An alternative plugin can also be the cxf-codegen-plugin from Apache CXF (link)

UPDATE

If you want to use the newer JakartaEE 9.0+ packages, you need to use the following plugin, keeping the same configurations:

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

and for jaxb:

<groupId>com.evolvedbinary.maven.mojohaus</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>3.0.0</version>
Brokenhearted answered 19/3, 2019 at 13:30 Comment(4)
Phase <phase>process-classes</phase>was breaking my build since the generated classes were not generated otherwise it's fine, thanks!Preeminence
it does not generate classes with the suffix "Service" for meNordine
This helped. had to update from <groupId>org.codehaus.mojo</groupId> --> to <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-maven-plugin</artifactId>. After that had to import few jakarta related dependencies.Foreclose
Be careful the block <configuration> must be outside of block <execution>, it must be at the same level of <plugin>Acrostic
K
4

Found this - https://github.com/mojohaus/jaxws-maven-plugin/issues/54#issuecomment-440597801 I used the same configuration as for org.jvnet.jax-ws-commons jaxws-maven-plugin. Think it is the same as org.codehaus.mojo, but don't 100% sure.

Tested with JDK 11. All XSD elements, ports and services are generated. You also need to add a few dependencies to your pom. Minimum:

        <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>
Kamchatka answered 29/12, 2018 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.