toogle sidebar button


  1. validate
  2. initialize
  3. generate-sources
  4. process-sources
  5. generate-resources
  6. process-resources
  7. compile
  8. process-classes
  9. generate-test-sources
  10. process-test-sources
  11. generate-test-resources
  12. process-test-resources
  13. test-compile
  14. process-test-classes
  15. test
  16. prepare-package
  17. package
  18. pre-integration-test
  19. integration-test
  20. post-integration-test
  21. verify
  22. install
  23. deploy


Built-in properties

  • ${basedir} represents the directory containing pom.xml
  • ${version} equivalent to ${project.version} (deprecated: ${pom.version})

Pom/Project properties

All elements in the pom.xml, can be referenced with the project. prefix. This list is just an example of some commonly used elements. (deprecated: {pom.} prefix)

  • ${} results in the path to your “target” directory, this is the same as ${}
  • ${} results in the path to your “target/classes” directory
  • ${} refers to the name of the project (deprecated: ${} ).
  • ${project.version} refers to the version of the project (deprecated: ${pom.version}).
  • ${} refers to the final name of the file created when the built project is packaged

Local user settings

Similarly, values in the user’s settings.xml can be referenced using property names with settings. prefix.

  • ${settings.localRepository} refers to the path of the user’s local repository

Environment variables

Environment variables can be referenced using the env prefix

  • ${env.M2_HOME} returns the Maven2 installation path.
  • ${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
  • <jvm>${java.home}../bin/java.exe</jvm>

Java system properties

All Java System Properties defined by the JVM.

Custom properties in the POM

User defined properties in the pom.xml.

  • ${my.filter.value} will result in hello if you inserted the above XML fragment in your pom.xml

Parent Project variables

How can parent project variables be accessed?

You can use the prefix: ${project.parent}.

A good way to determine possible variables is to have a look directly at the API. I’m currently using Maven 2.2.1, and to access the Parent you can use ${project.parent}. This will return an org.apache.maven.project.MavenProject instance.

To access the parent version: ${parent.version}.

Reflection Properties

The pattern ${someX.someY.someZ} can simply sometimes mean getSomeX().getSomeY().getSomeZ(). Thus, properties such as ${} is translated to getProject().getBuild().getDirectory().

Useful maven plugin goals

  • versions:display-dependency-updates - Display Dependency Updates
  • versions:display-plugin-updates - Display Plugin Updates
  • dependency:tree -Ddetail - Display Dependency Tree
  • dependency:list - Display Dependency List
  • help:effective-pom - Display Effective POM
  • help:effective-settings - Display Project Settings
  • help:system - Display System and Environment Variables
  • dependency:build-classpath - Display Build Class Path
  • dependency:get -Dartifact=org.apache.hadoop:hadoop-aws:321 - downloading artifact with dependencies from remote to local repo

Generating projects from archetype

Standalone project

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart

Web project

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

Enable Servlet 3.0+ API

The Servlet 3.0 API focuses on ease of development by making use of JSR 175 annotations to enable declarative-style programming. This allows to reduce XML configuration and use instead annotations or web hooks.

Servlet 3.0 compatible containers are Tomcat 7.x, Glassfish 3.x, JBoss AS 6.x/7.x and, Jetty 8.x.

Provide servlet 3.0 API in order to use it when developing. Not shipping with archive as when running server will provide implementation for that API.

pom.xml :


	<!-- compile only, deployed container will provide this -->


Update web.xml :

<web-app xmlns:xsi="" 
			id="WebApp_ID" version="3.0">



Enable Java 1.8

pom.xml :




Create single jar with all dependencies


Then run: java -jar project-1.0-SNAPSHOT-jar-with-dependencies.jar

Embedded services





mvn jetty:run

Open application



When changing static resources, changes are immediate. When changing java code, modified classes must be compiled, thus the best to execute: mvn package -DskipTests=true


Using In-Memory Database Maven Plugin it’s possible to set up local DB. Supported databases types: hsqldb, derby, h2. Comprehensive example using it with integration tests:



Sample data

-- Create the tables
CREATE TABLE app_sometable
   some_varchar varchar(100),
   some_numeric numeric,
   some_timestamp timestamp,
   some_blob blob
-- Insert the data
insert into app_sometable (some_varchar, some_numeric, some_timestamp, some_blob)
values ('unit_test_varchar',123,'1977-01-30-',null);

Run it

mvn inmemdb:run


  • URL: jdbc:derby://localhost/memory:test-data
  • Driver: org.apache.derby.jdbc.ClientDriver
  • Hibernate dialect: org.hibernate.dialect.DerbyDialect


To local Tomcat

See: Install and configure Tomcat server

Configure deployment process


Now we need to set up credentials to the local server outside the project configuration. Create ~/.m2/settings.xml with content:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns=""


Deploy application to local server

mvn tomcat7:deploy


Running *IT tests in a separated phase


mvn verify

Code coverage


Run one of:

test-compile org.jacoco:jacoco-maven-plugin:prepare-agent surefire:test org.jacoco:jacoco-maven-plugin:report

Skipping tests


  • mvn install -DskipTests - skip executing tests
  • mvn install -Dmaven.test.skip=true - skip compiling tests


Set version

  • mvn versions:set -DnewVersion=1.0.1-123 -DgenerateBackupPoms=false -X

Release to Maven Central repository

Prepare environment

Setup GnuPG

In order to sign package GnuPG library is required.

Install GnuPG

sudo apt-get install gnupg2

Generate or import keys

Import existing keys:

wget http://.../public.asc
gpg --import public.asc
wget http://.../secret.asc
gpg --allow-secret-key-import --import secret.asc

Generate and distribute public key to public key servers:

gpg --gen-key
gpg2 --list-keys 
gpg2 --list-secret-keys
gpg2 --keyserver hkp:// --send-keys C6EED57A

Prepare project

Perform release, deploy, publish

Perform release and deploy artifact to OSSRH with Maven Release Plugin

mvn release:clean release:prepare
mvn release:perform

Publish release to Maven Central repository

  • Go to .
  • Login with your credentials.
  • Locate and Examine Your Staging Repository.
  • Close repository in order to trigger the evaluations of the components against the requirements.
  • If everything went without issues, click Release button. This will move the components into the release repository of OSSRH where it will be synced to the Central Repository.