title: Generating sources by running a project's java class in Maven
body: <p>I'm converting a largish Ant build to Maven. As part of the Ant build, we have several steps which created Java classes by invoking one of the project's classes, simplified as:</p>
  
  <pre><code>javac SomeGenerator.java
  java  SomeGenerator  generated # generate classes in generated/
  javac generated/*.java
  </code></pre>
  
  <p>I've split each generator in its own Maven module, but I have the problem of not being able to run the generator since it's not yet compiled in the <code>generate-sources</code> phase.</p>
  
  <p>I've tried something similar to</p>
  
  <pre><code>        &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.1.1&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;generate-model&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;java&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;phase&gt;generate-sources&lt;/phase&gt;
  
                      &lt;configuration&gt;
                          &lt;mainClass&gt;DTOGenerator&lt;/mainClass&gt;
                          &lt;arguments&gt;
                              &lt;argument&gt;${model.generated.dir}&lt;/argument&gt;
                          &lt;/arguments&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  </code></pre>
  
  <p>Which sadly does not work, for the reasons outlined above. Splitting the code generators into two projects each, one for compiling the generator and another for generating the DTOs seems overkill.</p>
  
  <p>What alternatives are there?</p>
  
  <hr>
  
  <p>Using Maven 2.2.1.</p>