Jaxb:XSD中的两个声明在objectFactory类中引起冲突

问题描述

我使用jaxb2-maven-plugin从XSD生成Java源。

首先我遇到类似错误

org.xml.sax.SAXParseException: A class/interface with the same name "TypeX" is already in use. Use a class customization to resolve this conflict.

我通过应用具有以下内容的binding.xml来解决了所有问题:

...
    <jxb:bindings schemaLocation="../schema1.xsd">
        <jxb:bindings node="//xs:complexType[@name='TypeX']">
            <jxb:class name="TypeXFromSchema1"/>
        </jxb:bindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="../schema2.xsd">
        <jxb:bindings node="//xs:complexType[@name='TypeX']">
            <jxb:class name="TypeXFromSchema2"/>
        </jxb:bindings>
    </jxb:bindings>
...

但是在那之后,我开始遇到与相同类型有关的其他错误。我从错误日志中的行号推导出来。错误是:

com.sun.istack.SAXParseException2: Two declarations cause a collision in the ObjectFactory class.
    at com.sun.tools.xjc.ErrorReceiver.error (ErrorReceiver.java:56)
...

出什么问题了?从我的角度来看,我确切地告诉了生成的类名应该是什么样子,ObjectFactory应该根据此名称创建(所有的getter,setter以及生成的任何东西)。

或者我还必须做什么?我尝试使用

为架构指定其他包
<jxb:bindings schemaLocation="../schemas1.xsd">
    <jxb:schemaBindings>
        <jxb:package name="com.example.myschema1"/>
    </jxb:schemaBindings>
</jxb:bindings>

<jxb:bindings schemaLocation="../schema2.xsd">
    <jxb:schemaBindings>
        <jxb:package name="com.example.myschema2"/>
    </jxb:schemaBindings>
</jxb:bindings>

但是它以相同的错误结束。我也在pom.xml的“配置”部分中尝试过:

  <args>
    <arg>-XautoNameResolution</arg>
  </args>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)