title: How to generate java classes from multiple xsd with common schema using maven
body: <p>I'm trying to generate a java classes from multiple xsd files.
  But I get this error.</p>
  
  <blockquote>
    <p>org.xml.sax.SAXParseException; ... 'somelement' is already defined</p>
  </blockquote>
  
  <p>I think it's due to the common types that included multiple times.</p>
  
  <p>How can I generate the java classes with maven?</p>
  
  <p>I have the following schemas in a directory:</p>
  
  <p>xsd: </p>
  
  <ul>
  <li>EXAMPLE_QualifyRS.xsd</li>
  <li>EXAMPLE_QualifyRQ.xsd</li>
  <li>EXAMPLE_Peble_CommonTypes.xsd</li>
  <li>EXAMPLE_CommonTypes.xsd</li>
  <li>EXAMPLE_SimpleTypes.xsd</li>
  </ul>
  
  <p>EXAMPLE_QualifyRS.xsd</p>
  
  <pre><code>&lt;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"&gt;
      &lt;xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/&gt;
      &lt;xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/&gt;
      &lt;xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/&gt;
           &lt;xs:element name="someelement"&gt;...&lt;/xs:element&gt;
  </code></pre>
  
  <p>EXAMPLE_Peble_CommonTypes.xsd</p>
  
  <pre><code>&lt;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"&gt;
      &lt;xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/&gt;
  </code></pre>
  
  <p>EXAMPLE_QualifyRQ.xsd</p>
  
  <pre><code>&lt;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"&gt;
      &lt;xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/&gt;
      &lt;xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/&gt;
      &lt;xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/&gt;
          &lt;xs:element name="someelement"&gt;...&lt;/xs:element&gt;
  </code></pre>
  
  <p>And here is how I generate my class in maven</p>
  
  <pre><code>&lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;jaxb2-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;example-schema&lt;/id&gt;
                          &lt;phase&gt;generate-sources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;xjc&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;xsdPathWithinArtifact&gt;xsd&lt;/xsdPathWithinArtifact&gt;
                              &lt;addGeneratedAnnotation&gt;true&lt;/addGeneratedAnnotation&gt;
                              &lt;laxSchemaValidation&gt;true&lt;/laxSchemaValidation&gt;
                              &lt;laxSchemaValidation&gt;true&lt;/laxSchemaValidation&gt;
                              &lt;readOnly&gt;true&lt;/readOnly&gt;
                              &lt;verbose&gt;true&lt;/verbose&gt;
                              &lt;sources&gt;
                                  &lt;source&gt;src/main/resources/xsd&lt;/source&gt;
                              &lt;/sources&gt;
                              &lt;packageName&gt;com.example&lt;/packageName&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  </code></pre>