I've got a Maven project that runs perfectly inside Netbeans. How can I execute the application from the command-line (without Netbeans)?
2 Answers
There's a plugin for that: http://www.mojohaus.org/exec-maven-plugin/
$ mvn exec:java -Dexec.mainClass="com.mycompany.App"
Assuming com.mycompany.App
is you main class.

- 181,842
- 47
- 306
- 310
-
"-Dexec.mainClass needs to be replaced by -Dmain.class". Secondly the classpath is incorrectly set to "[...]\apache-maven-2.2.1\bin\..\boot\classworlds-1.1.jar". How do I correct this? – Gili Sep 11 '10 at 00:10
-
1@Gili what is the problem with the classpath exactly? Can you update the question to show the obtained result (and how it differs from the expected one). – Pascal Thivent Sep 11 '10 at 05:21
-
Marking as accepted because I no longer have the original project around and this answer seems correct (in theory, at least) :) – Gili Jun 15 '12 at 19:34
Using the Maven Exec Plugin and its exec:java
goal as suggested is a first option. And the command suggested is correct, you have to specify -Dexec.mainClass=VALUE
on the command line.
mvn exec:java -Dexec.mainClass=com.acme.Hello
Regarding your "classpath problem", well, you didn't describe it very clearly. What is your problem? What are your dependencies exactly? Just in case, there is a classpathScope
parameter allowing to define the scope of the classpath passed to the plugin. E.g.:
mvn exec:java -Dexec.classpathScope=compile -Dexec.mainClass=com.acme.Hello
As an alternative to the above plugin, there is MOP. What is MOP?
What is MOP?
MOP is a small utility for executing Java programs which are stored as artifacts like jars or bundles in a Maven repository.
MOP automatically deals with the following for you
- transitive dependencies
- downloading artifacts from remote repositories and caching them locally
- setting up your classpath

- 562,542
- 136
- 1,062
- 1,124