Jaxb:wsdl中的两个声明导致objectFactory类

时间:2017-12-23 12:09:26

标签: java affiliate maven-jaxb2-plugin

我想使用Affilinet API。它的一个WSDL文件在这里:

Affilinet AccountService.wsdl

我使用这个Maven插件来生成源:

Jaxb Maven Plugin

我的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.

但是如何使用来自网址的wsdl文件修复此问题?

schemaLocation不接受wsdl文件....

编辑:完整日志:

[ERROR] Error while generating code.Location [ https://api.affili.net/V2.0/AccountService.svc?wsdl{1,6200}].

com.sun.istack.SAXParseException2; systemId:https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber:1; columnNumber:6200;这是另一个宣言。

3 个答案:

答案 0 :(得分:1)

如果您有两个相互矛盾的定义,通常会发生这种情况。由于格式错误,因此判断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,将其格式化为人类可读的并在本地编译。这应该明确指出哪些部分会导致问题。

答案 1 :(得分:0)

我不得不更新问题。

可在此处找到较新版本。不过,lexicores的答案是对的。

如果您预计会出现进一步的问题,可以查看(以后这里):Jaxb - Multiple Errors with "Is already defined"

答案 2 :(得分:0)

面对同样的问题,我有多个模式,要确定哪些元素会导致冲突有点困难。添加jaxb绑定为重复的元素提供不同的名称后,我能够解析并生成ObjectFactory类。

示例:我在Product.xsdCustomerOrder.xsd中将“ Id”作为公共元素之一,因此必须在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>

这是我在execution中定义的pm.xml

                  <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>
相关问题