Maven Basics

Author: yifei / Created: April 4, 2018, 1:57 p.m. / Modified: April 4, 2018, 9:58 p.m. / Edit



Maven is built around the pom.xml file. In Maven, how to build your project is predefined in the Maven Build Life Cycles, Phases and Goals. The POM file describes what to build, but most often not how to build it. How to build it is up to the Maven build phases and goals.

Minimal POM file

Here is a minimal POM file:

4.0.0 com.jenkov java-web-crawler 1.0.0

this outputs MAVEN_REPO/com/jenkov/java-web-crawler/1.0.0/java-web-crawler-1.0.0.jar

Super POM

You can make a POM file explicitly inherit from another POM file. That way you can change the settings across all inheriting POM's via their common super POM. You specify the super POM at the top of a POM file like this:




mvn help:effective-pom shows the combined pom of parent and current

Running Maven

When executing the mvn command you pass the name of a build life cycle, phase or goal to it, which Maven then executes.

syntax: mvn phase:goal

Directory Structure

You must follow the maven directory structure

- src
  - main
    - java
    - resources
    - webapp
  - test
    - java
    - resources
- target

more here: Introduction to the Maven Standard Directory Layout


<project xmlns=""




external dependencies


snapshot dependencies

Snapshot dependencies are dependencies (JAR files) which are under development.



maven tries to pull dependencies from local, central, and remote repo

Local Repositores

it's defined in ~/.m2/settings.xml


Central Repositories

Maintained by the maven community

Remote Repositories

A remote repository is often used for hosting projects internal to your organization, which are shared by multiple projects.


Maven Build Cycles

When Maven builds a software project it follows a build life cycle. The build life cycle is divided into build phases, and the build phases are divided into build goals. Since you cannot execute the default life cycle directly, you need to execute a build phase or goal from the default life cycle.

1. default 
validate    Validates that the project is correct and all necessary information is available. This also makes sure the dependencies are downloaded.
compile Compiles the source code of the project.
test    Runs the tests against the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
package Packs the compiled code in its distributable format, such as a JAR.
install Install the package into the local repository, for use as a dependency in other projects locally.
deploy  Copies the final package to the remote repository for sharing with other developers and projects.
2. clean
3. site


Profiles let you use differvent build settings