我正在尝试使用 Maven 生成 JAXB 文件以供 Spring 框架使用,但 Maven 显示以下错误:
我知道它无法生成具有名称的文件,但我不确定如何解决该问题。到目前为止,我访问了以下链接。 1 , 2 , 3
org.xml.sax.SAXParseException; systemId: http://www5v80.elsyarres.net/service.asmx?wsdl; lineNumber: 5; columnNumber: 39; A class/interface with the same name "hello.wsdl.SearchFlights" is already in use. Use a class customization to resolve this conflict.
....
org.xml.sax.SAXParseException; systemId: http://www5v80.elsyarres.net/service.asmx?wsdl; lineNumber: 12; columnNumber: 43; (Relevant to above error) another "SearchFlights" is generated from here.
....
org.xml.sax.SAXParseException; systemId: http://www5v80.elsyarres.net/service.asmx?wsdl; lineNumber: 371; columnNumber: 42; A class/interface with the same name "hello.wsdl.GetFlightDetails" is already in use. Use a class customization to resolve this conflict.
....
Maven插件
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://www5v80.elsyarres.net/service.asmx?wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
我将以下 package-info.java
文件添加到 hello.wsdl
包中,但它没有帮助。
@XmlSchema(
namespace = "ElsyArres.API",
elementFormDefault = XmlNsForm.QUALIFIED)
package hello.wsdl;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
原文由 Daniel Newtown 发布,翻译遵循 CC BY-SA 4.0 许可协议
您面临的错误消息基本上表明您的 wsdl 的
types
部分中的某些名称被使用了两次。在您的情况下, 所有<element>
标签都与其相应类型具有相同的名称(定义为<complexType>
)。例子:
这是很不常见的。
基本上有两种选择可以解决这些问题:
使用自动名称解析
该插件将通过为每个冲突名称附加数字来解决所有命名冲突。在上面提到的 SearchFlights 案例中,这将导致生成 SearchFlights 和 SearchFlights2 。
更好的方法 是使用绑定文件提前解决所有名称冲突。绑定文件主要包含
XPATH
表达式和转换规则。附加到 每个 声明名称的绑定文件如下:jaxb:nameXmlTransform
还有其他选项,例如后缀和附加到其他类型的 xml 元素(如类型)。可悲的是,我无法使用
org.jvnet.jaxb2.maven2:maven-jaxb2-plugin
(但我确信有一个工作配置)尽管如此,它仍适用于
org.codehaus.mojo:jaxws-maven-plugin
和以下配置。