Run Maven Project from CLI

This is just a quick not on how to run a maven project from the CLI – command line interface.

  1. cd into the root directory of the project.
  2. Run mvn compile.
  3. Then, to execute a class with a main method (usually the Application class) execute the following Maven command:
mvn exec:java -Dexec.mainClass=[your class here]

For example, let’s say you have a class with a main method in called Application, and that class is in a package named com.myname.myproject. Then the command to execute the main method would be:

mvn exec:java -Dexec.mainClass=com.myname.myproject.Application

Leave a Reply

Your email address will not be published. Required fields are marked *