简体   繁体   English

maven-jaxb2-plugin失败,必须存在JAXB版本属性

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

I have the following configuration for maven-jaxb2-plugin : 我对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; org.xml.sax.SAXParseException; systemId: file:/home/hasancansaral/workspace/company/domain/src/main/xsd/delivery.wsdl; systemId:文件:/home/hasancansaral/workspace/company/domain/src/main/xsd/delivery.wsdl; lineNumber: 2; lineNumber:2; columnNumber: 366; columnNumber:366; JAXB version attribute must be present 必须存在JAXB版本属性

It doesn't make a difference if I run the plugin through IntelliJ IDEA or do a simple mvn clean jax2b:generate . 如果我通过IntelliJ IDEA运行插件或执行简单的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). 但是,可以在这里找到的模式成功完成该操作,因此我怀疑我的wsdl模式实际上是格式错误的,暂时无法公开,但是可以通过消息提供(我知道这没有太大帮助)公开发布,但如果问题出在架构中,我将在此处发布相关问题部分)。

Note: SOAP UI validates the schema as well. 注意: SOAP UI也会验证模式。

Note2: Same error is present with both jax2b-maven-plugin and maven-jax2b-plugin . 注意2: jax2b-maven-pluginmaven-jax2b-plugin都存在相同的错误。

TL;DR Your WSDL is not correct/suitable for XJC. TL; DR您的WSDL不正确/不适合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. 您将需要strup JAXB定制或将xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"到根元素。

The problem is that your WSDL contains a lot of JAXB customizations in the included schema. 问题在于您的WSDL在所包含的模式中包含许多JAXB定制。 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. JAXB定制是特定于供应商的东西,无论谁将其放入WSDL(应该是与供应商无关的规范)中,都做不到正确的事情。

Now the thing is that XJC, the JAXB schema compile expects certain bells and whistles when you have inline JAXB customizations. 现在的事情是,当您具有内联JAXB定制时,JAXB模式编译器XJC会遇到一些麻烦。 Like jaxb:version attribute on the root element. 就像根元素上的jaxb:version属性一样。 Which is, in this case, missing. 在这种情况下,这是丢失的。 It is present on the schema element but not on the root wsdl:definitions element. 它存在于schema元素上,但不在根wsdl:definitions元素上。 If you add it , compilation succeeds. 如果添加它 ,编译将成功。

This has nothing to do with JAXB plugins whatsoever. 这与JAXB插件无关。 If you try xjc -wsdl delivery.wsdl , you'll get the same error. 如果尝试使用xjc -wsdl delivery.wsdl ,则会收到相同的错误。

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. 因此,我建议修补WSDL。 Create a patch and apply it to the WSDL in a pre-code-generation step. 创建一个补丁并将其在预代码生成步骤中应用于WSDL。 I personally would strip all JAXB customizations from the WSDL as they have forgotten literally nothing there. 我个人将从WSDL中剥离所有JAXB定制,因为它们实际上什么也没忘记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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