Java Code generation from XSD/WSDL for Jakarta 4.0.0 using Maven Plugin

13k views Asked by At

I have wasted mutiple days trying to figure it out, how can something that seems pretty straightforward (generating code from a WSDL/XSD) be so extremly complicated. Are there any approaches? I feel I have tried them all, in diffrent versions using diffrent jaxb bindings and implementations in their diffrent versions

I tried using the following plugins:

<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>

No plugin is able to output jakarta Annotations and always failes bc some javax.xml Annotiation or com.sun.* Class is missing. At this point I am thinking about writing a plugin myself, because this is ridiculous, I just need a simple POJO with some annotations and dont want to write them myself when the xsd or wsdl changes.

Are there any approaches you guys used that work for Jakarta 4?

3

There are 3 answers

2
Максим Цюпко On BEST ANSWER

Try this one:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        *
    </parent>

    <artifactId>*</artifactId>

    <properties>
        <service.package>com.company</service.package>

        <jakarta.xml.ws-api.version>4.0.0</jakarta.xml.ws-api.version>
        <jaxws-rt.version>4.0.0</jaxws-rt.version>
        <jaxws-ri.version>4.0.0</jaxws-ri.version>
        <jaxws-maven-plugin.version>3.0.0</jaxws-maven-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.xml.ws</groupId>
            <artifactId>jakarta.xml.ws-api</artifactId>
            <version>${jakarta.xml.ws-api.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>${jaxws-rt.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-ri</artifactId>
            <version>${jaxws-ri.version}</version>
            <type>pom</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.sun.xml.ws</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>${jaxws-maven-plugin.version}</version>
                <configuration>
                    <wsdlDirectory>${basedir}/src/main/resources</wsdlDirectory>
                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                    <extension>true</extension>
                </configuration>
                <executions>
                    <execution>
                        <id>USER_INFO</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <wsdlFiles>
                                <wsdlFile>user_info.xml.wsdl</wsdlFile>
                            </wsdlFiles>
                            <packageName>${service.package}.userinfo</packageName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

All dependencies now are jakarta.xml instead of javax.xml.

0
Laurent Schoelens On

I know this question is quite old but for reference the following plugin has been updated this year with many changes :

<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>

The repository URL has been updated : https://github.com/highsource/jaxb-tools

It now contains all the org.jvnet.jaxb related tools, including the maven-plugin and the jaxb2-basics xjc-plugins

You can follow the migration guide in order to upgrade from 0.x versions to 2.x version (JAXB 2.3 javax), 3.x version (JAXB 3 jakarta) or 4.x version (JAXB 4 jakarta, jdk11)

For example, the plugin in v4 is now located at

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

and the jaxb2-basics are now here for generation :

<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>

and for jaxb-plugins runtime dependency :

<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-runtime</artifactId>
0
Dave Kentucky On

I have used the jaxws-maven-plugin for generation of code from WSDL and jaxb-maven-plugin for generating code from XSD. Here is the config I've used:

        <plugin>
            <groupId>org.jvnet.jaxb</groupId>
            <artifactId>jaxb-maven-plugin</artifactId>
            <version>4.0.0</version>
            <executions>
                <execution>
                    <id>generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>src/main/resources</schemaDirectory>
                <bindingDirectory>src/main/resources/xjb</bindingDirectory>
                <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>4.0.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <wsdlDirectory>src/main/resources</wsdlDirectory>
                <wsdlFiles>
                    <file>FiverxLinkService_01_10.wsdl</file>
                </wsdlFiles>
                <sourceDestDir>${project.build.directory}/generated-sources</sourceDestDir>
                <packageName>de.meona.ataxe.fiverx.wsdl</packageName>
            </configuration>
        </plugin>

Succesfully got java classes with imports from jakarta packages.