I'm trying to generate a java classes from multiple xsd files. In these schemas files there are multiple complexType or elements with the same name in different schemas.
Please note that I'm unable to change the schemas.
I created a binding file, but I'm still getting this error
EXAMPLE_QualifyRQ.xsd; ... 'myelement' is already defined
Is there anything I miss in my configuration?
All the schemas are in 1 directory for example:
xsd:
- EXAMPLE_QualifyRS.xsd
- EXAMPLE_QualifyRQ.xsd
- EXAMPLE_PurchaseRQ.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:element name="myelement">...</xs:element>
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.002" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:element name="myelement">...</xs:element>
EXAMPLE_PurchaseRQ.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:element name="myelement">...</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>
<xjbSources>
<xjbSource>src/main/resources/xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>
</plugin>
And my bindings
<?xml version="1.0" encoding="UTF-8"?>
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
extensionBindingPrefixes="xjc">
<globalBindings>
<serializable uid="1"/>
<xjc:javaType name="java.time.LocalDateTime" xmlType="xs:dateTime" adapter="com.example.adapter.LocalDateTimeAdapter"/>
<xjc:javaType name="java.time.LocalDate" xmlType="xsd:date" adapter="com.example.adapter.LocalDateAdapter"/>
</globalBindings>
<bindings schemaLocation="../xsd/EXAMPLE_QualifyRS.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.qualify.response"/>
</schemaBindings>
<bindings node="//xs:element[@name='myelement']">
<class name="QualifyMyElement"/>
</bindings>
</bindings>
<bindings schemaLocation="../xsd/EXAMPLE_QualifyRQ.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.qualify.request"/>
</schemaBindings>
<bindings node="//xs:element[@name='myelement']">
<class name="QualifyMyElement"/>
</bindings>
</bindings>
<bindings schemaLocation="../xsd/EXAMPLE_PurchaseRQ.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.purchase"/>
</schemaBindings>
<bindings node="//xs:element[@name='myelement']">
<class name="PurchaceMyElement"/>
</bindings>
</bindings>
</bindings>