MOBI BOOT CAMP CORP. logoLearning Buddy
  • SIGN IN
  • Introduction
  • 1. Build Tools & Project Structure
    • Maven Build System
    • Maven Commands
    • Gradle Build System
    • Java Enterprise Edition (JEE)
  • 2. The Web Layer (Servlets & JSP)
  • 3. Design Patterns & Architecture
  • 4. Persistence Foundations (SQL & JDBC)
  • 5. Object-Relational Mapping (ORM)
  • 6. Modern Web Services & Microservices
  • 7. Hands-on Project

Maven Commands

In this lesson, you will learn some common commands that are used with Maven. To run all these commands from the terminal, ensure that you are inside the project root folder that contains the pom.xml file. Then, run the commands below:

mvn clean

This command deletes the compiled classes and other Maven-generated artifacts of your Java programs.

By default, Maven keeps all the .class files and all the other generated artifacts in a folder called target, which is also at the project root folder. By running the above command, the target folder is deleted.

mvn package

This is the main command to package your application as per the <packaging> element details in your pom.xml.

This command compiles all your .java files to .class files and packages it as a jar or war file, typically along with other required artifacts. The exact file type is given in the <packaging> element of your pom.xml file. The packaged file, along with all the other generated files, will be placed inside the target folder.

In the process of packaging, Maven fetches all the dependencies that are described in the pom.xml file from remote repositories. It also runs test cases and generates test reports along the way. The resulting artifact of this command could be a jar or war file, and will be described in the <packaging> element of your pom.xml file.

mvn clean package

This command combines the above two commands, so it will first delete the target folder (clean) and then create the target folder with all the artifacts as described in the mvn package command above.

mvn install

This is similar to the mvn package command, except it takes it a step further by copying the packaged jar or war file from the target folder into your local .m2 Maven repository.

mvn package -Dmaven.test.skip=true

This command does the exact same job as mvn package, except all the test cases are skipped.

mvn -Dtest=MyTestCase test

To run a single test, you can use this command. In this example, you can run the test case called MyTestCase by running the above command from the project root. Note that you can replace MyTestCase with any other test case class. The full path of the Java test case file is not required.

mvn appengine:run

If you have the Maven App Engine plugin defined in your pom.xml, then this command will package the project, deploy it to the local App Engine server, and start the server on your local machine.

mvn appengine:deploy

To deploy an App Engine project to a public-facing Google Cloud website, this command is used. The two commands above are specific to Google's App Engine projects.

Privacy Policy | Terms & Conditions