Search code examples
javajakarta-eexsdjava-17java-platform-module-system

Migrating from jaxb xjc generation to jakarta and Java 17


We are in the process of investigating the migration of our application from JDK8 to JDK17. Some of our modules use wsdl based web services, some others make use of .xsd schemas etc. Regardless, we make use of JAXWS and JAXB apis that are now removed from JDK since version 11 and moved to Jakarta.

I have successfully started generating sources from .wsdl and .xsd files using the jakarta dependencies and the source is properly generated with jakarta imports

import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElementRef;

whereas previously it was using javax.xml.bind. stuff which is not available at compile time anymore. My problem is that although I have successfully generated schema based sources, the new generators produce different code (class names, accessors etc.) and I'd like to confirm that this is the intended behavior before proceeding with a refactor.

Example:

Our .xsd contains the following:

<xsd:complexType name="ForkStepType">
    <xsd:annotation>
        <xsd:appinfo>
            <jxb:class name="ForkStep"/>
        </xsd:appinfo>
    </xsd:annotation>
    <xsd:complexContent>
        <xsd:extension base="tns:LinearStepType">
            <xsd:sequence/>
            <xsd:attribute name="forkLevel" type="tns:ForkLevelType" use="required"/>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

The old xjc generator using jaxb version 2.2.11 would generate a class named ForkStep, I'm guessing based on the jxb:class element. The jakarta 3.0.1 generator on the other hand generates a class named ForkStepType which I'm guessing comes from the xsd:complexType element.

Is this expected behavior? Were the old implementations incorrect when it comes to interpreting the specification or is there a flag/spec target version that I should be aware of in order to properly reproduce our app's existing behavior?


Solution

  • The problem comes from forgetting to upgrade the jaxb schema to the jakarta uri and version 3.0.

    Specifically

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        jxb:version="1.0"
    

    must be changed to

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
        jxb:version="3.0"
    

    For reference, similar changes must be done to .wsdl files as well, for example xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"xmlns:jaxws="https://jakarta.ee/xml/ns/jaxws"