首页 > 解决方案 > jaxb2-maven-plugin -- com.sun.istack.SAXParseException2:属性“类型”已定义。使用 <jaxb:property> 解决此冲突

问题描述

我正在使用 jaxb2-maven-plugin 从 XSD 文件构建 java 类。我在 Maven 构建期间遇到错误,表明“类型”属性存在命名冲突

[ERROR] file:/Users/me/Documents/workspace/purchase-order-service/src/main/xsd/ProcessShipment.oagi9.xsd [1431,58] 
com.sun.istack.SAXParseException2: Property "Type" is already defined. Use &lt;jaxb:property> to resolve this conflict.

我相信要解决这个问题,我需要创建一个外部绑定文件来重命名属性。我查看了一些资源,但无法使其正常工作-同样的错误。似乎甚至没有检测到我的绑定文件。

pom.xml

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>${jaxb2-maven.version}</version>
            <executions>
                ...
                <execution>
                    <id>xjc-processshipment</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <xjbSources>
                            <xjbSource>src/main/xsd/ProcessShipment.oagi9.xjb</xjbSource>
                        </xjbSources>
                        <sources>
                            <source>src/main/xsd/ProcessShipment.oagi9.xsd</source>
                        </sources>
                        <outputDirectory>${basedir}/target/generated-sources/process-shipment
                        </outputDirectory>
                        <clearOutputDir>false</clearOutputDir>
                    </configuration>
                </execution>
            </executions>

我试图转换为 Java 对象的 src/main/xsd/ProcessShipment.oagi9.xsd 文件可以在这里下载https://drive.google.com/file/d/10KoS9CeinUbOTQ5Nc2Gh9dmiS1eLxNs4/view?usp=sharing

我正在尝试使用 src/main/xjb/bindings.xjb 来修复映射冲突

<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!--
Change since version 2.0 of the j-m-p:

Note that the schemaLocation path must point to the XSD file
relative to *this* file, rather than the basedir.
-->
<jxb:bindings schemaLocation="../xsd/ProcessShipment.oagi9.xsd" node="//xsd:schema">
  <jxb:bindings node="//xs:element[@ref='type']">
<jxb:property name="DeprecatedTypeAttribute"/>
  </jxb:bindings>
  <jxb:bindings node="//xs:element[@ref='Type']">
  <jxb:property name="DeprecatedTypeAttribute"/>
  </jxb:bindings>
</jxb:bindings>

</jxb:bindings>

谁能指出我正确的方向?我仍然遇到同样的错误,我认为这是因为我的 bindings.xjb 没有被拾取,而且我的绑定配置对于我正在尝试做的事情可能是错误的。感谢您的任何建议。

标签: javaxmlmavenjaxb

解决方案


推荐阅读