title: Managing JAXB-generated classes in a Maven project
body: <p>I have a Maven-based project, in which I trying to add some JAXB classes automatically generated by the "jaxb2-maven-plugin" Maven plugin.  However, my first cut has me in a circular dependency loop:</p>
  
  <ul>
  <li>Because these JAXB classes aren't generated yet, my other sources which reference them have compilation errors.  </li>
  <li>Because those other sources have compilation errors, these JAXB classes don't get generated.</li>
  </ul>
  
  <p>It seems like there are two obvious possibilities for solving this:</p>
  
  <ol>
  <li>Comment-out the broken references, so that the project builds and the JAXB classes are automatically generated.  Then copy those generated sources from <code>/target</code> into <code>/src/main/java</code>, so that references to them won't cause compilation errors.</li>
  <li>Create an entirely separate project, consisting of nothing but the JAXB stuff.  Include it as a dependency in my main project.</li>
  </ol>
  
  <p>Am I missing something here?  Option #1 seems flat-out ridiculous... that just <strong><em>can't</em></strong> be the manner in which people use JAXB.  Option #2 seems more rational, but still rather inefficient and cumbersome.  I really have to take on the overhead of an entirely separate project just to use JAXB?  </p>
  
  <p>Are there any more elegant approaches that developers use to reference JAXB-generated classes in the same project where the Maven plugin generates them?</p>
  
  <p><strong>UPDATE:</strong>  By request, here is the relevant portion of my POM:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;!-- configure the compiler to compile to Java 1.6 --&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.6&lt;/source&gt;
                  &lt;target&gt;1.6&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;       
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb2-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;generate-sources&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;xjc&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;!-- The name of your generated source package --&gt;
                  &lt;packageName&gt;com.mypackage&lt;/packageName&gt; 
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;  
  &lt;/build&gt;
  </code></pre>
  
  <p>When I run <code>mvn clean package</code>, I DO see my JAXB sources being generated beneath the <code>/target</code> subdirectory.  However, those generated sources are not being automatically added to the classpath for the compile phase.</p>
  
  <p><strong>POST-RESOLUTION UPDATE:</strong>  It turns out that my compilation issues had more to do with the fact that I was running in Eclipse, and its Maven integration has some issues with "jaxb2-maven-plugin".  See <a href="https://stackoverflow.com/questions/10387610/maven-jaxb2-xjc-plugin-m2e-plugin-execution-not-covered/12010610#12010610">this StackOverflow question</a> for more detail on that issue and its resolution.</p>