cxf-codegen-plugin and jaxb-maven-plugin for Java 21 and higher

556 Views Asked by At

I am upgrading Java from 1.8 to 21 and spring boot from 2.5 to 3.2.2 for one of my applications ..

I get this error  

    Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.1.10:wsdl2java (generate-sources) on project :
Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.1.10:wsdl2java failed: 
    A required class was missing while executing org.apache.cxf:cxf-codegen-plugin:3.1.10:wsdl2java: 

what is the right way to upgrade these plugins , I read a lot of articles online and each one suggets something and when I try those I get some other errors and its also confusing .. could someone kindly point out the right way to replace the cxf-codegen-plugin and jaxb-maven-plugin for Java 21 and higher ..

Here is my POM file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.2</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>21</java.version>
        <log4j2.version>2.17.0</log4j2.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>19.12.0.0</version>
        </dependency>
        <dependency>
            <groupId>de.siegmar</groupId>
            <artifactId>logback-gelf</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.5.3</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated-sources/</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/abc.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
<!--                https://github.com/highsource/jaxb-tools/wiki/JAXB-Tools-Migration-Guide-->
                <groupId>org.jvnet.jaxb</groupId>
                <artifactId>jaxb-maven-plugin</artifactId>
                <version>2.0.9</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl/abc/</schemaDirectory>
                    <generateDirectory>${project.build.directory}/generated-sources/</generateDirectory>
                    <schemaIncludes>
                        <include>WSSoap.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
1

There are 1 best solutions below

1
Laurent Schoelens On

If you are targeting SpringBoot 3, you must know that this major version change includes moving from javax to jakarta based package.

I guess taking the following versions of the two plugins should do the job for you :

  • org.apache.cxf:cxf-codegen-plugin : 4.0.3 (jaxb3 - jakarta based)
  • org.jvnet.jaxb:jaxb-maven-plugin : 4.0.0 (jaxb4 - jakarta based, jdk11 baseline)