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.

Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.

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.

This entry was posted in Software Development and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Posted November 8, 2013 at 12:21 am | Permalink

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

  2. Posted January 26, 2014 at 3:39 am | Permalink

    Also, there is maven exec plugin

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.