How to Run Maven Based Java Application From Command Line
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 secureHTML5 App
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.