简体   繁体   中英

maven-jaxb2-plugin fails with JAXB version attribute must be present

I have the following configuration for maven-jaxb2-plugin :

            <!-- https://mvnrepository.com/artifact/org.jvnet.jaxb2.maven2/maven-jaxb2-plugin -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <strict>false</strict>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>com.mycompany.project.domain.wsdl</generatePackage>
                    <schemas>
                        <schema>
                            <url>url or file</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>

and it is failing with:

[ERROR] Error while parsing schema(s).Location [ file:/home/hasancansaral/workspace/company/domain/src/main/xsd/delivery.wsdl{2,366}].

org.xml.sax.SAXParseException; systemId: file:/home/hasancansaral/workspace/company/domain/src/main/xsd/delivery.wsdl; lineNumber: 2; columnNumber: 366; JAXB version attribute must be present

It doesn't make a difference if I run the plugin through IntelliJ IDEA or do a simple mvn clean jax2b:generate . However, the action is successful with the schema that can be found here , so I am suspecting of my wsdl schema being actually malformed, which I cannot make public for the moment, but can provide via messages (I know that it is not much help to public as is, but if the problem is in the schema I will post the related problematic part of it here).

Note: SOAP UI validates the schema as well.

Note2: Same error is present with both jax2b-maven-plugin and maven-jax2b-plugin .

TL;DR Your WSDL is not correct/suitable for XJC. You'll need strup JAXB customizations or add xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1" to the root element.

The problem is that your WSDL contains a lot of JAXB customizations in the included schema. This is a bad idea. JAXB customization are vendor-specific stuff, whoever put those in a WSDL (which is supposed to be vendor-neutral spec) did not do the right thing.

Now the thing is that XJC, the JAXB schema compile expects certain bells and whistles when you have inline JAXB customizations. Like jaxb:version attribute on the root element. Which is, in this case, missing. It is present on the schema element but not on the root wsdl:definitions element. If you add it , compilation succeeds.

This has nothing to do with JAXB plugins whatsoever. If you try xjc -wsdl delivery.wsdl , you'll get the same error.

There might be some magic option to suppress this problem, but it's hard to figure out. So I'd suggest to patch the WSDL. Create a patch and apply it to the WSDL in a pre-code-generation step. I personally would strip all JAXB customizations from the WSDL as they have forgotten literally nothing there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM