Jaxb:wsdl 中的两个声明导致 objectFactory 发生冲突 class
Jaxb: Two declarations in a wsdl cause a collision in the objectFactory class
我想与 Affilinet 一起工作 API。它的一个 WSDL 文件在这里:
我使用这个 Maven 插件来生成源代码:
我的Pom.xml插件配置:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.logon</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/Logon.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema2-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/PublisherInbox.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema3-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/AccountService.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
所以,在编译这个时,我得到一个错误:
com.sun.istack.SAXParseException2; systemId: https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber: 1; columnNumber: 2127; Two declarations cause a collision in the objectFactory class.
但是我如何使用来自 url 的 wsdl 文件修复此问题?
schemaLocation 不接受 wsdl 文件....
编辑:完整日志:
[ERROR] Error while generating code.Location [ https://api.affili.net/V2.0/AccountService.svc?wsdl{1,6200}].
com.sun.istack.SAXParseException2;系统编号:https://api.affili.net/V2.0/AccountService.svc?wsdl;行号:1;列数:6200;这是另一个声明。
如果您有两个相互冲突的定义,通常会发生这种情况。很难判断您的 WSDL 到底出了什么问题,因为它的格式很糟糕。但通常这将类似于两个元素,它们在转换为 Java.
后获得相同的方法名称
您通常可以通过绑定自定义来解决这个问题。这是一个例子:
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings
schemaLocation="http://schemas.opengis.net/citygml/texturedsurface/1.0/texturedSurface.xsd"
node="/xs:schema">
<jaxb:bindings node="xs:element[@name='_Appearance']">
<jaxb:factoryMethod name="AAppearance"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
所以你要做的就是找出问题的确切原因,编写并应用绑定。我要做的第一件事是下载 WSDL,将其格式化为人类可读的格式并在本地进行编译。这应该清楚地指出是哪些部分导致了问题。
遇到了同样的问题,我有多个模式,很难确定哪些元素导致了冲突。在添加 jaxb 绑定以为重复的元素提供不同的名称后,我能够解析并生成 ObjectFactory class。
示例:我将 "Id" 作为 Product.xsd
和 CustomerOrder.xsd
中的公共元素之一,因此必须在 common.xjb 文件中提供绑定。
<jaxb:bindings schemaLocation="../../Common/XSD/Product.xsd" node="//xs:element[@name='Id']">
<jaxb:class name="ProductId" />
</jaxb:bindings>
<jaxb:bindings schemaLocation="../../Common/XSD/CustomerOrder.xsd" node="//xs:element[@name='Id']">
<jaxb:class name="CustomerOrderId" />
</jaxb:bindings>
这是我在pm.xml
中定义的execution
<execution>
<id>Outbound</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
<arg>-XtoString</arg>
</args>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>some.package.name</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</schemaDirectory>
<bindingDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</bindingDirectory>
<strict>false</strict>
<bindingIncludes>
<include>*.xjb</include>
</bindingIncludes>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>${jaxb2.basics.version}</version>
</plugin>
</plugins>
</configuration>
</execution>
我想与 Affilinet 一起工作 API。它的一个 WSDL 文件在这里:
我使用这个 Maven 插件来生成源代码:
我的Pom.xml插件配置:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.logon</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/Logon.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema2-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/PublisherInbox.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema3-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/AccountService.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
所以,在编译这个时,我得到一个错误:
com.sun.istack.SAXParseException2; systemId: https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber: 1; columnNumber: 2127; Two declarations cause a collision in the objectFactory class.
但是我如何使用来自 url 的 wsdl 文件修复此问题?
schemaLocation 不接受 wsdl 文件....
编辑:完整日志:
[ERROR] Error while generating code.Location [ https://api.affili.net/V2.0/AccountService.svc?wsdl{1,6200}].
com.sun.istack.SAXParseException2;系统编号:https://api.affili.net/V2.0/AccountService.svc?wsdl;行号:1;列数:6200;这是另一个声明。
如果您有两个相互冲突的定义,通常会发生这种情况。很难判断您的 WSDL 到底出了什么问题,因为它的格式很糟糕。但通常这将类似于两个元素,它们在转换为 Java.
后获得相同的方法名称您通常可以通过绑定自定义来解决这个问题。这是一个例子:
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings
schemaLocation="http://schemas.opengis.net/citygml/texturedsurface/1.0/texturedSurface.xsd"
node="/xs:schema">
<jaxb:bindings node="xs:element[@name='_Appearance']">
<jaxb:factoryMethod name="AAppearance"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
所以你要做的就是找出问题的确切原因,编写并应用绑定。我要做的第一件事是下载 WSDL,将其格式化为人类可读的格式并在本地进行编译。这应该清楚地指出是哪些部分导致了问题。
遇到了同样的问题,我有多个模式,很难确定哪些元素导致了冲突。在添加 jaxb 绑定以为重复的元素提供不同的名称后,我能够解析并生成 ObjectFactory class。
示例:我将 "Id" 作为 Product.xsd
和 CustomerOrder.xsd
中的公共元素之一,因此必须在 common.xjb 文件中提供绑定。
<jaxb:bindings schemaLocation="../../Common/XSD/Product.xsd" node="//xs:element[@name='Id']">
<jaxb:class name="ProductId" />
</jaxb:bindings>
<jaxb:bindings schemaLocation="../../Common/XSD/CustomerOrder.xsd" node="//xs:element[@name='Id']">
<jaxb:class name="CustomerOrderId" />
</jaxb:bindings>
这是我在pm.xml
execution
<execution>
<id>Outbound</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
<arg>-XtoString</arg>
</args>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>some.package.name</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</schemaDirectory>
<bindingDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</bindingDirectory>
<strict>false</strict>
<bindingIncludes>
<include>*.xjb</include>
</bindingIncludes>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>${jaxb2.basics.version}</version>
</plugin>
</plugins>
</configuration>
</execution>