5

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.

Hasan Can Saral
  • 2,198
  • 2
  • 28
  • 53
  • 1
    First I would suggest to use [jaxb2-maven-plugin](http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.3.1/)...and using an uptodate version...If you checked against another schema means you schema must be the culprit... – khmarbaise Mar 15 '17 at 13:07
  • @khmarbaise Thanks for the comment. I have tried both plugins, and up-to-date versions of both of them. I too suspect from a malformed schema, and appreciate if you could look at it. Do you mind if I send you the schema over chat? – Hasan Can Saral Mar 15 '17 at 13:10
  • @khmarbaise And I can successfully consume the webservice with [SoapUI](https://www.soapui.org/). – Hasan Can Saral Mar 16 '17 at 08:57
  • 1
    @khmarbaise "First I would suggest to use jaxb2-maven-plugin..." - why? – lexicore Mar 16 '17 at 13:17
  • @HasanCanSaral Show your WSDL. Could you put a reproducing example? PR here: https://github.com/highsource/maven-jaxb2-plugin-support, I'll take a look. – lexicore Mar 16 '17 at 13:19
  • @lexicore Done, Appreciate your help. Please see [here](https://github.com/highsource/maven-jaxb2-plugin-support/pull/3) for PR, didn't open an issue for the plugin itself, as I am not sure if it's a plugin issue or simply a bad schema. – Hasan Can Saral Mar 17 '17 at 08:03
  • @HasanCanSaral Thank you, I've seen it. The problem is that you have inline `jaxb:class` customizations. Therefore XJC expects `jaxb:version` on schema. I'll take a look on the weekend. – lexicore Mar 17 '17 at 09:03
  • @lexicore Thank you, I appreciate it very much. The problem is that the schema is provided by some 3rd party and it's not a file but an actual URL. So I have downloaded it and am trying to resolve the issue by editing the file, as I have no control over wsdl provided from the URL. Looking forward for your answer then. Thanks! – Hasan Can Saral Mar 17 '17 at 09:11
  • I have the exact same issue. Have you found a solution? – Ognjen Mišić Feb 03 '19 at 22:45
  • @OgnjenMišić Yes, the accepted answer actually solved my issue. – Hasan Can Saral Feb 04 '19 at 07:31
  • @HasanCanSaral how exactly? How did you "patch the wsdl"? The WSDL I'm supposed to consume I have access to locally only (but I think that would suffice?), the soapui can read it properly while my wsimport / xjc still throw these errors.. – Ognjen Mišić Feb 04 '19 at 07:33
  • You save it to your resources folder/filesytem and point it to the file you saved in your configuration, then you can update it. The actual owner doesn’t have to do anything. – Hasan Can Saral Feb 04 '19 at 07:35
  • Yes, I did save it, the thing I want to ask is how exactly do I update it? I'm not that experienced in dealing with broken WSDLs and have no clue where to start :( – Ognjen Mišić Feb 04 '19 at 07:57
  • To be clear, I did add the jxb namespace and the jxb:version to the root element (wsdl:definitions), but then when I do the wsimport / mvn goal I get a message saying that jaxb version is required – Ognjen Mišić Feb 04 '19 at 08:15
  • @OgnjenMišić I have just added `xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"` to the root element as in the answer and it resolved my issue. That was the only thing I did. – Hasan Can Saral Feb 04 '19 at 08:40
  • What is your root element? or something else? – Ognjen Mišić Feb 04 '19 at 09:35
  • No the root element of the XML/WSDL file itself. The outmost element. – Hasan Can Saral Feb 04 '19 at 09:40
  • In my case, my outermost element is . What should I wrap it with so i can have the jxb bindings? Could you show me your two or three top elements please? – Ognjen Mišić Feb 04 '19 at 10:25
  • I have updated `.xjb` file. It's root element is as follows: `` – Hasan Can Saral Feb 04 '19 at 11:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187866/discussion-between-ognjen-misic-and-hasan-can-saral). – Ognjen Mišić Feb 04 '19 at 14:34

1 Answers1

10

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.

lexicore
  • 39,549
  • 12
  • 108
  • 193