Maven cheatsheet

Below is cheatsheet for maven, these are fairly basic things:

POM : Project Object Model
A POM contains all the information about a project pertaining to:

Lets begin with the beginning steps:

The root element in POM is “project”

<project xmlns="" xmlns:xsi=""

Naming a project :

1.) groupId – com.example
2.) artifactId – TaskMaster
“groupId:artifactId” denotes a single project
3.) version – 1.0
so full name is – groupId:artifactId:version

Packaging :
this could have values pom, jar, maven-plugin, ejb, war, ear, rar, par
When no packaging is declared, Maven assumes the artifact is the default: jar.

Hence our first block of POM looks like :


Dependencies One can add all the dependencies like JARs inside the root element project

<project> ā€¦...

Maven will try to get the dependency from your local repository (~/.m2/repository), if not found, then it will download from the default Maven central repository ā€“
This entry of default repository is mentioned in Super POM which is inherited by all POMs.

Multiple repositories
In case there is an enterprise repository from which the dependencies should be downloaded, we could add multiple repositories.
There are 2 different ways that you can specify the use of multiple repositories.
1.The first way is to specify in a POM which repositories you want to use, by using repositories tag:

      <name>your custom repo</name>

2. The second way could be to make a profile in ~/.m2/settings.xml give repository url and activate it.

         <name>your custom repo</name>


See the complete documentation here.

Sometimes it may happen that a project can not be downloaded from a repository then we could:

1.Install the dependency locally using the install plugin.

mvn install:install-file -Dfile=non-maven-proj.jar -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar

This install plugin will create a POM for you with the given address.

We can define parent POM, its just another pom with packaging type as pom.

<project xmlns=""


Dependencies and plugins are few of the important elements in the parent POM that are inherited by its children.

It can be used like this:


Build Settings
The “build” element: Conceptually it is divided into 2 segments
a.) build for project
b.) build for profiles

  <!-- "Project Build" contains more elements than just the BaseBuild set -->

      <!-- "Profile Build" contains a subset of "Project Build"s elements -->


Another feature of build elements is specifying where resources exist within your project. Resources are not (usually) code. They are not compiled, but are items meant to be bundled within your project or used for various other reasons, such as code generation.


Beyond the standard coordinate of groupId:artifactId:version, there are elements which configure the plugin or this builds interaction with it.
Plugins are extensions or plugins developed to support additional features in maven. For example, the Apache Tomcat Maven Plugin provides goals to manipulate WAR projects within the Apache Tomcat servlet container. You can run your War Apache Maven project through Apache Maven without deploying your WAR file to an Apache Tomcat instance.
This plugin can be used by the plugin attribute in the POM.


This is just a list of few of the important things in POM, the complete reference is here.


One thought on “Maven cheatsheet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s