failed to execute goal org.jvnet.jaxb2.maven2 after changing the java version from java 8 to java 17

134 Views Asked by At

These are the errors related to jaxb I am getting after I have changed the java version from java 8 to java 17.

BUILD FAILURE
[INFO] Finished at: 2024-02-22T18:46:54+05:30
[INFO]

[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.0: generate (WSDL2JAVA) on project ENService: Execution WSDL2JAVA of goal org.jvnet.jaxb2.maven2:maven-jaxh2 plugin:0.13.0:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.0:generate: com/sun/xml/bind/api/ErrorListener

ERROR

ERROR] realm plugin>org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.0 ERROR] strategy org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy

ERROR

] urls[0] = file:/C:/Users/PJ78398/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin/0.13.0/maven-jaxb2-plugin-0.13.0.jar

ERROR] urls[1] = file:/C:/Users/P378398/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin-core/0.13.0/maven-jaxb2-plugin-core-0.13.0.jar

ERROR] urls[2] file:/C:/Users/P378398/.m2/repository/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar ERROR] urls[3]file:/C:/Users/P378398/.m2/repository/com/sun/org/apache/xml/internal/resolver/20050927/resolver-20050927.jar

ERROR] urls[4] file:/C:/Users/P378398/.m2/repository/org/sonatype/plexus/plexus-build-api/e.e.7/plexus-build-api-0.0.7.jar ERROR] urls[5] file:/C:/Users/PJ78398/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar

ERROR] urls[6] = file:/C:/Users/P378398/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15. jar

ERROR] urls[7] file:/C:/Users/P378398/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb22-plugin/0.13.0/maven-jaxb22-plugin-0.13.0.jar file:/C:/Users/P378398/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar

ERROR] urls[8] =

ERROR] urls[9] file:/C:/Users/P378398/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar ERROR] urls[10] file:/C:/Users/P378398/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.4/maven-plugin-annotations-3.4.jar

ERROR] Number of foreign imports: 1

ERROR

] import: Entry[import from realm ClassRealm[maven.api, parent: null]]

And this the plugin I am using

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.13.0</version>
    <executions>
        <execution>
            <id>WSDL2JAVA</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <schemaDirectory>config</schemaDirectory>
                <schemaLanguage>WSDL</schemaLanguage>
                <schemaIncludes>
                    <include>*.wsdl</include>
                </schemaIncludes>
            </configuration>
        </execution>
    </executions>
</plugin>

I have tried this but still the build is fail .

Certainly! Here's how you can update the pom.xml file in the ENservice module according to the blog post:

<project>
    ...
    <properties>
        <!-- Set the JDK version to 17 -->
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <!-- Update the maven-compiler-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>

            <!-- Update the maven-jaxb2-plugin -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <executions>
                    <execution>
                        <id>WSDL2JAVA</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>config</schemaDirectory>
                            <schemaLanguage>WSDL</schemaLanguage>
                            <schemaIncludes>
                                <includes>
                                 <include>*..wsdl</include>
                           </schemaIncludes>

And these dependencies also

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.1</version>
</dependency>

Building is still failing after this. Any suggestions ?
Thank you in advance :)

2

There are 2 best solutions below

0
Laurent Schoelens On

Since you seem to target JAXB 2.3, you should check the migration guide to get the latest version of the plugin (choose 2.0.9 version which is current latest version supporting JAXB 2.3)

Move from the following :

<!-- Update the maven-jaxb2-plugin -->
<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.14.0</version>
...
</plugin>

To the following :

<plugin>
  <groupId>org.jvnet.jaxb</groupId>
  <artifactId>jaxb-maven-plugin</artifactId>
  <version>2.0.9</version>
...
</plugin>

You should also move to the latest jaxb-api / jaxb-runtime dependencies

<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.3</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.9</version>
</dependency>
0
VijayC On

Since you are upgrading to Java 17 there will be compatibility issues between open source dependencies. You can search in https://mvnrepository.com by copying the above artifact-id and update with the latest versions for all the dependencies listed in your pom.xml. Also in your pom.xml it will be nice to have like this for better readability:

<configuration>
      <maven.compiler.release>17</maven.compiler.release>
</configuration>

And in the maven-compiler-plugin (Above version 3.6):

<configuration>
    <release>17</release>
</configuration>