I'm trying to generate a java classes from multiple xsd files. But I get this error.
org.xml.sax.SAXParseException; ... 'somelement' is already defined
I think it's due to the common types that included multiple times.
How can I generate the java classes with maven?
I have the following schemas in a directory:
xsd:
- EXAMPLE_QualifyRS.xsd
- EXAMPLE_QualifyRQ.xsd
- EXAMPLE_Peble_CommonTypes.xsd
- EXAMPLE_CommonTypes.xsd
- EXAMPLE_SimpleTypes.xsd
EXAMPLE_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>
EXAMPLE_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"/>
EXAMPLE_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>
And here is how I generate my class in 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>