Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 685
Chris Avatar asked Nov 17 '25 02:11

Chris


2 Answers

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.

like image 170
Максим Цюпко Avatar answered Nov 18 '25 18:11

Максим Цюпко


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>
like image 26
Laurent Schoelens Avatar answered Nov 18 '25 17:11

Laurent Schoelens