Search code examples
jaxbjax-wswsimportxmlbeansxmlbeans-maven-plugin

Wsimport failing when building with JDK 21


I am trying to upgrade a service from Java 8 to JDK 17. I am pretty new to Maven. Below is the maven pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>${testversion}</version>
    <packaging>jar</packaging>
    <name>Test Project</name>
    <url></url>

        <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <fork>true</fork>
                    <source>21</source>
                    <target>21</target>
                </configuration>
            </plugin>
            
            
            <plugin>
              <groupId>com.sun.xml.ws</groupId>
              <artifactId>jaxws-maven-plugin</artifactId>
              <version>2.3.7</version>
              <executions>
                <execution>
                  <goals>
                    <goal>wsimport</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <wsdlDirectory>${wsdlDir}</wsdlDirectory>
                <bindingDirectory></bindingDirectory>
                <verbose>true</verbose>
                <sourceDestDir>${basedir}/src/test/java</sourceDestDir>
                <extension>true</extension>
                <xjcArgs>
                  <xjcArg>-Xsetters</xjcArg>
                </xjcArgs>
              </configuration>
              <dependencies>
                <dependency>
                  <groupId>org.jvnet.jaxb</groupId>
                  <artifactId>jaxb2-basics</artifactId>
                  <version>2.0.9</version>
                </dependency>
              </dependencies>
            </plugin>
            
            
        </plugins>
    </build>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.sun.xml.ws</groupId>
                <artifactId>jaxws-rt</artifactId>
                <version>2.3.7</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

When try to build this using Maven, I am getting an error while parsing the wsdl files.

parsing WSDL...

[ERROR] Unexpected <bindings> appears at line 5 column 17
  line 5 of http://dummy.pseudo-schema#schema2

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.jvnet.jax_ws_commons.jaxws.Invoker.main(Invoker.java:74)
Caused by: com.sun.tools.ws.wscompile.AbortException
        at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:114)
        at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2265)
        at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:164)
        at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:111)
        at com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:413)
        at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:180)
        at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:158)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        ... 2 more

Below is the jax-ws binding file being used(removed some details due to policies)

<?xml version="1.0" encoding="UTF-8"?>
<bindings version="2.1" wsdlLocation=""
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        xmlns="http://java.sun.com/xml/ns/jaxb" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl">
    
    <globalBindings>
        <javaType name="java.util.Date" xmlType="xs:date"
                  parseMethod=""
                  printMethod=""
        />
        <javaType name="java.util.Date" xmlType="xs:dateTime"
                  parseMethod=""
                  printMethod=""
        />
        <xjc:serializable/>
    </globalBindings>
</bindings>


The same configuration worked when building the project using Java 8. Can someone let me know what the issue is here exactly? I am pretty new to these plugins so having a hard time finding the issue.

Edit:

wsimport is working now using the suggestion by Laurent

Facing build issues for one of the xml-beans generation POM. Building with Openjdk 21. Below is the POM.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test-xmlbeans</artifactId>
<version>${testversion}</version>
<packaging>jar</packaging>
<name>Test XMLBeans Generation Project</name>
<url></url>

<build>
<resources>
       <resource>
            <directory>${wsdlDir}</directory>
            <targetPath>xsd</targetPath>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xmlbeans-maven-plugin</artifactId>
            <version>2.3.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>xmlbeans</goal>
                    </goals>
                </execution>
            </executions>
            <inherited>true</inherited>
            <configuration>
                <schemaDirectory>${wsdlDir}</schemaDirectory>

                <noUpa>true</noUpa>
                <noVDoc>true</noVDoc>
                <memoryInitialSize>64m</memoryInitialSize>
                <memoryMaximumSize>512m</memoryMaximumSize>
                <verbose>true</verbose>
                <debug>true</debug>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>2.4.0</version>
    </dependency>
</dependencies>

Below is the error I am getting during the build

Caused by: org.codehaus.mojo.xmlbeans.XmlBeansException:XmlBeans compile failed:    
xml ErrorLoading wsdl file test.wsdl
xml ErrorProcessing 1 schema(s) in test.wsdl

Solution

  • New answer

    From what I understand, you're trying to migrate only from JDK8 to JDK21 based on your comments. You should then stick to javax-based packages (if no other upgrades planned)

    <plugin>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-maven-plugin</artifactId>
      <version>2.3.7</version>
      <executions>
        <execution>
          <goals>
            <goal>wsimport</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <wsdlDirectory>${wsdlDir}</wsdlDirectory>
        <bindingDirectory></bindingDirectory>
        <verbose>true</verbose>
        <!-- you should generate sources in a target subdirectory -->
        <sourceDestDir>${basedir}/src/test/java</sourceDestDir>
        <extension>true</extension>
        <xjcArgs>
          <!-- based on usage of jaxb2-basics -->
          <xjcArg>-Xsetters</xjcArg>
        </xjcArgs>
      </configuration>
      <dependencies>
        <dependency>
          <!-- move from org.andromda.thirdparty.jaxb2_commons:collection-setter-injector to jaxb2-basics -->
          <groupId>org.jvnet.jaxb</groupId>
          <artifactId>jaxb2-basics</artifactId>
          <version>2.0.9</version>
        </dependency>
      </dependencies>
    </plugin>
    

    XMLBeans answer

    Since the plugin is quite outdated (last release in 2009), I'd suggest to move to the maven-plugin equivalent of JAXB-Tools

    Here is a sample configuration which is equivalent to your's from my understanding :

    <plugin>
        <groupId>org.jvnet.jaxb</groupId>
        <artifactId>jaxb-maven-plugin</artifactId>
        <version>2.0.9</version>
        <configuration>
            <schemaDirectory>${wsdlDir}</schemaDirectory>
        </configuration>
        <executions>
            <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    I'd also suggest you to add the dependency of jaxb-ri in your dependencies since it's no more provided by the JDK since JDK9.

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.9</version>
    </dependency>
    

    Initial answer

    Three points for the above configuration :

    1. Your header definition is incorrect for jakarta migration

    It should be the following

    <bindings version="3.0" wsdlLocation=""
            xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
            xmlns="https://jakarta.ee/xml/ns/jaxb"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl">
    

    If you're not targeting jakarta (for example, having Spring below v6 / SpringBoot below v3) but want only Java17, then the plugin itself should be changed to the following :

    <plugin>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.3.7</version>
        <!-- configuration like above here -->
    </plugin>
    

    2. I've seen a wrong dependency in your plugin

    In general, provide only needed dependencies on your plugin. Overriding could lead to error in config.

    The following should be removed or replace by it's jakarta equivalent :

    <dependency>
      <groupId>javax.jws</groupId>
      <artifactId>jsr181-api</artifactId>
      <version>1.0-MR1</version>
    </dependency>
    

    Jakarta's coordinates :

    <dependency>
        <groupId>jakarta.jws</groupId>
        <artifactId>jakarta.jws-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    

    3. I've also seen you're using the following plugin which is not under active dev :

    <dependency>
      <groupId>org.andromda.thirdparty.jaxb2_commons</groupId>
      <artifactId>collection-setter-injector</artifactId>
      <version>1.0</version>
    </dependency>
    

    This plugin is in org.jvnet.jaxb:jaxb-plugins:4.0.0 you can find here and can be activated with -Xsetters (documentation of the plugin here. Just replace the above dependency with the new one.

    For jakarta-based version, use this :

    <dependency>
      <groupId>org.jvnet.jaxb</groupId>
      <artifactId>jaxb-plugins</artifactId>
      <version>4.0.0</version>
    </dependency>
    

    For non-jakarta-based version, use this :

    <dependency>
      <groupId>org.jvnet.jaxb</groupId>
      <artifactId>jaxb2-basics</artifactId>
      <version>2.0.9</version>
    </dependency>
    

    Another point : some plugins in org.andromda.thirdparty.jaxb2_commons groupId are currently integrated in 4.0.1 of jaxb-plugins.