Replacement for wsimport since JDK 11
Asked Answered
P

6

27

I'm currently working on a project which needs wsimport, but we use JDK 11 and I discovered, that wsimport was removed from JDK since this version.

I searched for answers and I tried adding this dependency, but it's not working at the moment.

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

Is there any replacement for wsimport that I'm not aware of?

Thank you!

Porscheporsena answered 12/11, 2018 at 17:2 Comment(3)
2.3.1 is the latest version; try that!Henrique
Use com.sun.xml.ws:jaxws-maven-plugin:2.3.2 from Jakarta EE (github.com/eclipse-ee4j/metro-jax-ws/tree/master/jaxws-ri/…) once it's released. Currently it's available in OSS Sonatype Staging repo (oss.sonatype.org/content/groups/staging/com/sun/xml/ws/…) and I hope will be released soon. For more details see github.com/javaee/metro-jax-ws/issues/1251 .Tiffanitiffanie
One alternative is Apache CXF's wsdl2java.Isometropia
C
7

Today, you can use a fork as a direct replacement of 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. It works well with jdk11

Carissacarita answered 3/3, 2019 at 15:26 Comment(0)
A
6

The latest version of the plugin (2.6 by now) works with Java 11.

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

Ashjian answered 4/3, 2020 at 23:22 Comment(0)
G
3

I'm going to add what I've found through my research into upgrading to JDK11 in case it helps someone else.

Wsimport was deprecated as a part of the JDK, but was open sourced to the Eclipse Foundation. You can download it with the following link:

[https://repo1.maven.org/maven2/com/sun/xml/ws/jaxws-ri/2.3.0/jaxws-ri-2.3.0.zip][1]

They have changed wsimport from an executable to a bat/sh script that calls the jaxws-tools.jar file. I have not actually seen it work and always get a ClassNotFoundException: javax.activation.DataSource. I have even changed their script to include the javax.activation-api-1.2.0.jar and it still does not work. It does not matter if I attempt a build through Maven or run it command-line.

This was my plugin configuration:

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

I also used the following so that I could develop on Windows and Jenkins could build on 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>
Gummite answered 11/1, 2019 at 15:7 Comment(2)
the link provided above doesn't work anymore. Can you please provide the link which works!Color
It can be found here, if you go up a level you will see the latest version: repo1.maven.org/maven2/com/sun/xml/ws/jaxws-ri/2.3.0Gummite
S
1

The jaxws-maven-plugin is not updated yet for JDK 11. There is a pull request open on the project, but it is not merged yet.

A temporary solution for wsimport is proposed here: https://github.com/javaee/metro-jax-ws/issues/1251#issuecomment-441424365, which probably works fine on Linux.

On our project we are working with Windows environments and we fixed the wsimport according to the following example:

<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>
Scenery answered 16/1, 2019 at 11:43 Comment(0)
P
1

Actually, none of the provided answers work.

What works is this:

  1. Add this plugin (configure it according to your needs):
<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. Add this dependency:
<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. Execute mvn clean generate-resources (or any later phase from the Default Lifecycle).
Pub answered 22/11, 2023 at 10:28 Comment(0)
P
-4

It's works, finally! Just in case someone has the same problem :

I wanted to use maven build to generate the sources, with this 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>

But the solution is to run wsimport directly with the console :

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

And of course, I'm using JDK 11

Porscheporsena answered 13/11, 2018 at 12:56 Comment(1)
JDK 11 does not have wsimport tool. So I am not sure how you are doing what you described.Tiffanitiffanie

© 2022 - 2024 — McMap. All rights reserved.