Getting Started with Maven | Maven Preparation | Maven Basics

Maven logo

Basic Maven Commands

  • maven [options] [<goal(s)>] [<phase(s)>]

Examples of commands are as follows.

# Package the project.
mvn package

# Delete all files generated through the Maven build, then package the project.
mvn clean install

Maven Life Cycle

Maven has a predefined build order. This is called the life cycle, and each build step in the life cycle is called a phase.

The life cycle is divided into several steps (phases), and each phase has dependencies.

  • Default life cycle

    • compile: Compiles the source code.
    • test: Runs unit tests. (By default, a unit test failure is treated as a build failure.)
    • package: Packages compiled class files and resource files into a file such as a war or jar.
    • install: Deploys the packaged file to the local repository. (USER_HOME/.m2/)
    • deploy: Deploys the packaged file to a remote repository. (Nexus or Maven Central repository)
  • clean life cycle

    • clean: Deletes all files generated through the Maven build.
  • site life cycle

  • site: Creates a documentation site for the project using Maven configuration file information.

  • site-deploy: Deploys the generated documentation site to the configured server.