JAXB2 Maven插件xjc解析错误:org.xml.sax.SAXParseException:意外的 出现

问题描述 投票:1回答:1

我想使用JAXB2 maven插件从WSDL文件生成Java对象,以将soap服务用作客户端。

[当我将此插件用作“ jaxb2:generate”并在下面进行配置时:

...
        <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>tr.com.foo.dummy.model</generatePackage>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <bindingDirectory>${project.basedir}/src/main/resources</bindingDirectory>
                    <bindingIncludes>
                        <bindingInclude>*.xjb</bindingInclude>
                    </bindingIncludes>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </plugin>

...

我收到一个错误的说法:

[INFO] --- maven-jaxb2-plugin:0.14.0:generate (default-cli) @ hmbs ---
[INFO] Latest timestamp of the source resources is [2020-03-13 18:10:23.000], earliest timestamp of the target resources is [2020-03-06 18:06:36.000].
[INFO] Sources are not up-to-date, XJC will be executed.
[ERROR] Error while parsing schema(s).Location [ file:/home/yigithan/playground/foo/bar/src/main/resources/wsdl/foo.wsdl{23,87}].
org.xml.sax.SAXParseException: Unexpected <xs:element> appears at line 23 column 87 
...

我的WSDL文件就像:

<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s1="http://tempuri.org/AbstractTypes"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
                  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" version="1.0">
            <xs:element name="Insert">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" maxOccurs="1" name="custom" type="tns:Custom"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Custom">
                <xs:sequence>
                    <xs:element minOccurs="1" maxOccurs="1" name="foo" type="xs:int"/>
                    <xs:element minOccurs="1" maxOccurs="1" name="bar" type="xs:int"/>
                    <xs:element minOccurs="1" maxOccurs="1" name="baz" type="xs:long"/> 
                    <xs:element minOccurs="1" maxOccurs="1" name="qux" type="xs:dateTime"/>
                </xs:sequence>
            </xs:complexType>
...

并且错误位置在包含“ qux”元素的行中,并且{23,87}点是“ qux”的type =“ xs:dateTime”。如您所见,没有任何意外的元素。还是我错过了一点?

java soap jaxb wsdl jaxb2-maven-plugin
1个回答
0
投票

好的,我已经解决了问题。这是一条非常漫长的解决之路。发生了两个问题。第一个是我首先问这个问题的原因,因为WSDL文件是作为DOCX文件发送给我的,并且即使我在WSDL内复制粘贴了文件内容,也需要重新格式化文件文件。通过重新格式化,我不是在讲xml结构。就像在开玩笑,但删除空白行并重新暗示该文件有效。

下一个问题在类似的地方以“意外序列”出现:

<s:schema targetNamespace="http://tempuri.org/AbstractTypes">
            <s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
            <s:complexType name="StringArray">
                <s:complexContent>
                    <s:restriction base="soapenc:Array">
                        <s:sequence>
                            <s:element maxOccurs="unbounded" minOccurs="0" name="String" type="s:string"/>
                        </s:sequence>
                    </s:restriction>
                </s:complexContent>
            </s:complexType>
        </s:schema>

其原因是JAXB2无法处理编码类型。因此,如果发生无关错误,请首先尝试重构xml文件,以防xml构造错误,然后确保插件与您使用的类型兼容。

© www.soinside.com 2019 - 2024. All rights reserved.