Reputation: 158341
If I have understood correctly, I need to type this to run my project from maven:
mvn compile
mvn exec:java -Dexec.mainClass="com.foo.bar.blah.Main"
Is there a way I can make this simpler? Optimally I would like to just do
mvn run
Upvotes: 5
Views: 7410
Reputation: 22308
A little more configuration, a little less command line parameters ;-)
using the very same exec:java plugin, you can configure your task in the pom.xml, then execute it in a simpler fashion by mapping your goal to the run step of the lifecycle, like this example shows.
Upvotes: 5
Reputation: 358
1) Create a new profile called "run" (or another name of your choice)
<profiles>
<profile>
<id>run</id>
2) Set the profile's default goal to "verify" (or you can choose "install", choosing a phase after compile will ensure that the code will automatically be compiled before running the class)
<profiles>
<profile>
<id>run</id>
<build>
<defaultGoal>verify</defaultGoal>
3) Add the exec-maven-plugin to this profile (see this), but configure it to run in the 'verify' phase.
<execution>
<phase>test</phase>
4) You can now run your class using the following:
mvn -Prun
Upvotes: 6
Reputation: 9162
As the above example shows, you can wrap that plugin into a separate profile. Take a look at the 3rd solution
Upvotes: 1
Reputation: 16439
Sadly, no `(as far as I know). If you ahve a web application you could use Jetty plugin to run it doing:
mvn jetty:run
but for standalone apps, you need the exec plugin.
Upvotes: 0