title: How to execute an already compiled jar while building my project in Maven
body: <p>I am developing a library and I need to automatically generate a .java file before compiling. I found out a the <code>maven-exec-plugin</code> and I configured it in this way</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.2.1&lt;/version&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;id&gt;generate-city-enum&lt;/id&gt;
        &lt;phase&gt;generate-sources&lt;/phase&gt;
        &lt;goals&gt;
          &lt;goal&gt;java&lt;/goal&gt;
        &lt;/goals&gt;
        &lt;configuration&gt;
          &lt;executable&gt;java&lt;/executable&gt;
          &lt;mainClass&gt;org.codeforamerica.open311.city_enum_builder.EnumBuilder&lt;/mainClass&gt;
          &lt;arguments&gt;
            &lt;argument&gt;-jar&lt;/argument&gt;
            &lt;argument&gt;city_enum_builder.jar&lt;/argument&gt;
            &lt;argument&gt;cities.json&lt;/argument&gt;
            &lt;arguments&gt;output.java&lt;/arguments&gt;
          &lt;/arguments&gt;
        &lt;/configuration&gt;
      &lt;/execution&gt;
   &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>The problem is that running <code>mvn -e compile</code> I get the following error:</p>
  
  <p><code>java.lang.ClassNotFoundException: org.codeforamerica.open311.city_enum_builder.EnumBuilder</code></p>
  
  <p>However, this is the main class, and, indeed, if I execute <code>java -cp .:city_enum_builder.jar org.codeforamerica.open311.city_enum_builder.EnumBuilder cities.json output.java</code> it works.</p>
  
  <p>In addition, this .jar doesn't need to specify a class in order to get executed (<code>java -jar city_enum_builder.jar cities.json output.java</code> works as well).</p>
  
  <p>Thank you.</p>