【发布时间】:2020-03-13 14:51:51
【问题描述】:
我想使用 JAXB2 maven 插件从 WSDL 文件生成 Java 对象,以作为客户端使用肥皂服务。
当我使用这个插件作为“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"。如您所见,没有意外的元素。还是我遗漏了什么?
【问题讨论】:
-
问题是什么?
-
很抱歉,如果结构不正确。简而言之,当我将 jaxb2:generate 与所有这些一起使用时,我得到一个错误。解析架构时出错。位置 [file:/a.wsdl{23, 87}] org.xml.sax.SAXParseException: Unexpected
出现在第 23 行第 87 列是错误,但正如我发布的结构那里没有其他元素。 -
你粘贴的部分看起来不错,能否提供完整的wsdl?
-
我不能,这不是个人项目。但我会尽量缩短它并尝试。如果缩短时会得到相同的错误,我会发布它。很抱歉缺少完整的 wsdl,它不是一个开源项目,如果我直接发布完整版本会遇到麻烦。
标签: java soap jaxb wsdl jaxb2-maven-plugin