I would like to have a Maven goal trigger the execution of a java class. I’m trying to migrate over a Makefile with the lines:
neotest:
mvn exec:java -Dexec.mainClass="org.dhappy.test.NeoTraverse"
And I would like mvn neotest to produce what make neotest does currently.
Neither the exec plugin documentation nor the Maven Ant tasks pages had any sort of straightforward example.
Currently, I’m at:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions><execution>
<goals><goal>java</goal></goals>
</execution></executions>
<configuration>
<mainClass>org.dhappy.test.NeoTraverse</mainClass>
</configuration>
</plugin>
I don’t know how to trigger the plugin from the command line, though.
With the global configuration that you have defined for the exec-maven-plugin:
invoking
mvn exec:javaon the command line will invoke the plugin which is configured to execute the classorg.dhappy.test.NeoTraverse.So, to trigger the plugin from the command line, just run:
Now, if you want to execute the
exec:javagoal as part of your standard build, you’ll need to bind the goal to a particular phase of the default lifecycle. To do this, declare thephaseto which you want to bind the goal in theexecutionelement:With this example, your class would be executed during the
packagephase. This is just an example, adapt it to suit your needs. Works also with plugin version 1.1.