Home > Software Development > How to Run Maven Based Java Application From Command Line

How to Run Maven Based Java Application From Command Line

October 28th, 2013 Leave a comment Go to comments

It’s pretty straight forward to run Maven based projects in NetBeans IDE. For some projects that involve console related capabilities, you have to run it from OS console. One example is projects that use the JANSI APIs for colorful console output (see my last post for a sample). If you run the code within IDE, you won’t see the colors as would in a console.

While you can run the compiled code from console like any other Java applications, I found it’s not easy to get all the jars defined in the pom.xml as dependencies. There got to be an easier way that run the code from command line.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure


After a bit search, I found the exec-maven-plugin which is included in the Netbeans IDE if you download the all in one edition. Here is the command I used:

c:\Users\steve\git\TestApp>"c:\Program Files\NetBeans 7.3.1\java\maven\bin\mvn" exec:java -Dexec.mainClass="org.doublecloud.ShowColorText"

Note that you should first get into the directory with the pom.xml file of your project so that the plugin can get hold of the pom.xml for its dependent jar files. Also, the mainClass is case sensitive and should be typed exactly as shown above.

Although I got the problem while working with Netbeans, it’s not really much related to Netbeans. The solution can be used with any Maven project with any other IDEs.

Categories: Software Development Tags: , , ,
  1. November 8th, 2013 at 00:21 | #1

    Hey Steve, Thanks a lot for sharing this. The guide is very useful and well written.

  2. January 26th, 2014 at 03:39 | #2

    Also, there is maven exec plugin

  1. No trackbacks yet.