• Make sure %JAVA_HOME% is set (points to the root of the JDK)
  • Add the Maven bin/ folder to %PATH%

The repository will be in C:\Users\%username%\.m2\repository

Basic commands

Create a project

mvn archetype:generate \
    -DgroupId=ch.frattino \
    -DartifactId=<name of your artifact> \
    -DarchetypeArtifactId=maven-archetype-quickstart \

Generate Eclipse project files

mvn eclipse:eclipse

In case you add a new dependency, rerun this.

To get the source code too :

mvn eclipse:eclipse -DdownloadSources

To get the source code and the JavaDoc :

mvn eclipse:eclipse -DdownloadSources -DdownloadJavadocs

Build and package a project

mvn package


Find a library

For example, let's search for log4j. Google this : log4j

First result, open maven-metadata.xml. You'll find that :


Add a dependency


Deploy to local repository

mvn install

Deploy to remote repository

Resources and variables

Add resources

Just add them to src/main/resources or src/test/resources.

More infos

Filter resources

To use variables in your static resources :


To load variables from a filter (.properties file) :


To define properties in your POM :


Examples of variables :

Variable Description Example
${} Application name maven-test
${pom.version} Application version 1.0-SNAPSHOT
${} Full build name maven-test-1.0-SNAPSHOT
${settings.localRepository} User local repository C:\\Users\\cfr\\.m2\\repository
${java.version} Java property (here : Java version) 1.8.0_66
${user.home} Java property (here : User home) C:\\Users\\cfr
${} Any property from filter
${} Any property from POM file hello
${} Property from command line
mvn process-resources

If you just want to test the filtering of resources, just run

mvn process-resources

and look into target/classes.

More infos


So that JavaDoc is generate when you run “mvn site”, add this in your POM :


The Javadoc will be visible under Project Reports > JavaDocs

Build more than one projects at once



In Maven, an archetype is a template of a project which is combined with some user input to produce a working Maven project that has been tailored to the user's requirements.


  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project