我正在尝试从多个 xsd 文件生成一个 java 类。但我得到这个错误。
org.xml.sax.SAXParseException;...“一些元素”已经定义
我认为这是由于包含多次的常见类型。
如何使用 maven 生成 java 类?
我在目录中有以下模式:
xsd:
- 示例_QualifyRS.xsd
- 示例_QualifyRQ.xsd
- 示例_Peble_CommonTypes.xsd
- 示例_CommonTypes.xsd
- 示例_SimpleTypes.xsd
示例_QualifyRS.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/>
<xs:element name="someelement">...</xs:element>
示例_Peble_CommonTypes.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.000" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
示例_QualifyRQ.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.001" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/>
<xs:element name="someelement">...</xs:element>
这是我在 Maven 中生成课程的方式
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>example-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<xsdPathWithinArtifact>xsd</xsdPathWithinArtifact>
<addGeneratedAnnotation>true</addGeneratedAnnotation>
<laxSchemaValidation>true</laxSchemaValidation>
<laxSchemaValidation>true</laxSchemaValidation>
<readOnly>true</readOnly>
<verbose>true</verbose>
<sources>
<source>src/main/resources/xsd</source>
</sources>
<packageName>com.example</packageName>
</configuration>
</execution>
</executions>
</plugin>