title: Defining package names for common XSD's with xjc and bindings
body: <p>I'm trying to generate Java classes from several specific XSD's with <code>xjc</code>. Those schemas have some definitions in common, so they import a number of common XSD's. In particular, they can include from zero to all of the common XSD's. </p>
  
  <p>I'd like to generate all classes from an specific XSD to a specific package, but keeping the generated classes for the common schemas in a common package, so they don't get repeated for each specific schema in the source tree.</p>
  
  <p>I've learnt that custom bindings can be used to specify packages on a per-schema basis, with for instance: </p>
  
  <pre><code>&lt;jxb:bindings schemaLocation="common1.xsd" node="/xsd:schema"&gt;
      &lt;jxb:schemaBindings&gt;
          &lt;jxb:package name="mypackage.commonclasses"/&gt;
      &lt;/jxb:schemaBindings&gt;
  &lt;/jxb:bindings&gt;
  </code></pre>
  
  <p>I've got the following structure: </p>
  
  <pre><code>schemas
  | - common
  | | - common1.xsd --&gt; XSD with common types #1
  | | - ...
  | | - commonN.xsd --&gt; XSD with common types #N
  | | - commonBindings.xjb --&gt; Defines package "mypackage.commons" for common*.xsd
  | - specific1
  | | - specific1.xsd --&gt; Includes ../common/common{1-N}.xsd
  | | - specific1.xjb --&gt; Defines package "mypackage.specific1" for specific1.xsd
  | - specificN
  | | - specificN.xsd --&gt; Includes only ../common/common1.xsd
  | | - specificN.xjb --&gt; Defines package "mypackage.specificN" for specificN.xsd
  </code></pre>
  
  <p>It all works fine with: </p>
  
  <pre><code>xjc -b schemas/specific1
      -b schemas/common 
      schemas/specific1/specific1.xsd
  </code></pre>
  
  <p>It generates the classes for <code>specific1.xsd</code> in <code>mypackage.specific1</code> and the common classes in <code>mypackage.commons</code>. But when I try to generate the classes for <code>specificN</code>, <code>xjc</code> throws the following error: </p>
  
  <pre><code>[ERROR] "file:/drive/dir/schemas/common/common1.xsd" is not a part of
   this compilation. Is this a mistake for "/drive/dir/schemas/common/commonBindings.xjb"?
    line 2 of file:/drive/dir/schemas/common/commonBindings.xjb
  </code></pre>
  
  <p>I get this error repeated for every common XSD not imported in any specific xsd. </p>
  
  <p>Is there any way I can make <code>xjc</code> ignore the bindings in <code>commonBindings.xjb</code> that aren't used in the XSD I'm generating the classes for?</p>
  
  <p>Or, am I aiming in the wrong direction by using this approach, and should be, for instance, using annotations in the specific xsd? I'd like to avoid modifying the schemas if possible.</p>