Reputation: 312
I am developing a library and I need to automatically generate a .java file before compiling. I found out a the maven-exec-plugin
and I configured it in this way
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>generate-city-enum</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<executable>java</executable>
<mainClass>org.codeforamerica.open311.city_enum_builder.EnumBuilder</mainClass>
<arguments>
<argument>-jar</argument>
<argument>city_enum_builder.jar</argument>
<argument>cities.json</argument>
<arguments>output.java</arguments>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
The problem is that running mvn -e compile
I get the following error:
java.lang.ClassNotFoundException: org.codeforamerica.open311.city_enum_builder.EnumBuilder
However, this is the main class, and, indeed, if I execute java -cp .:city_enum_builder.jar org.codeforamerica.open311.city_enum_builder.EnumBuilder cities.json output.java
it works.
In addition, this .jar doesn't need to specify a class in order to get executed (java -jar city_enum_builder.jar cities.json output.java
works as well).
Thank you.
Upvotes: 0
Views: 176
Reputation: 5279
I suppose you confuse the parameters for the exec:exec
goal (which spawns an external process) with exec:java
(which just executes some Java class in Mavens VM).
(So for your example, <executable>java</executable>
will be ignored (so no java.exe called) and obviously your class itself doesnt know how to resolve classpaths.
So add the project providing your city_enum_builder.jar as dependency to your exec-maven-plugin
and it should work.
And dont forget to check http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html for more details.
Upvotes: 1