Paco Abato
Paco Abato

Reputation: 4065

Error marshalling old xsd file with jaxb2-maven-plugin 3.1.0

I have an xsd file which I use to generate DTO files with jaxb2-maven-plugin 2.5.0 under Java 8.

Now I migrated to jaxb2-maven-plugin 3.1.0 (forced by previous migration to Java 11) and I'm getting this error:

org.xml.sax.SAXParseException: not an external binding file. The root element must be {https://jakarta.ee/xml/ns/jaxb}bindings but it is {http://www.w3.org/2001/XMLSchema}schema

The xsd file starts like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="https://www.xxxxx.es/xxxxx/ApiEstandar"
    targetNamespace="https://www.xxxxx.es/xxxxx/ApiEstandar"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    
    <xs:complexType name="GenericRequest"/>
    
    <xs:complexType name="GenericResponse">
        <xs:sequence>
            <xs:element name="codigoRespuesta" type="xs:string" />
            <xs:element name="descripcionRespuesta" type="xs:string" />

If I change (like it seems to ask the previous error message) the xmlns:xs value to:

<xs:schema xmlns:xs="https://jakarta.ee/xml/ns/jaxb"

Then Eclipse complains about "xs:string" name not being resolved.

I'm not sure about how to configure correctly the xsd file.

EDIT: Answering to Laurent Schoelens I'm not using binding files and the plugin configuration in pom.xml is this one:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <locale>en</locale>
                <packageName>com.xxxxx.services.xxxxxservice.soap.services.model</packageName>
                <sources>
                    <source>${project.basedir}/src/main/resources/xsd/APIEstandar_v1.0.xsd</source>
                </sources>
            </configuration>
        </plugin>

Upvotes: 0

Views: 164

Answers (1)

Laurent Schoelens
Laurent Schoelens

Reputation: 2848

Starting from v3, the maven-plugin org.codehaus.mojo:jaxb2-maven-plugin targets JAXB3, which is jakarta-based.

If you need JDK11 support and v2.x of the jaxb2-maven-plugin doesn't bring support of JDK11 : you can check at org.jvnet.jaxb:jaxb-maven-plugin:2.0.9 plugin which is quite similar to Codehaus plugin and supports JDK11, JDK17 and even JDK21.

Upvotes: 1

Related Questions