The Project Object Model (POM)

A Maven2-enabled project always comes with a pom.xml file which contains the Project Object Model (POM) for this project. The POM contains every important piece of information about your project, which can be your project description, versioning or distribution information, dependencies and much more. It is essentially a one-stop-shopping for finding anything related to your project.

In its most basic form, a POM has the following structure :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache</groupId>
<artifactId>maven</artifactId>
<packaging>jar</packaging>
<version>2.0</version>
<name>Maven 2.0</name>
<url>http://maven.apache.org</url>
</project>

Since every bit of information about your project comes from the POM, it is very important to take the time to set up the encoding correctly. You can't imagine how many problems it will save you from later on.

 
You can already spot a few key elements :

One POM to rule them all

The POM is the basic unit of work in Maven. This is important to remember because Maven is inherently project-centric in that everything revolves around the notion of a project. Every task you ask Maven to perform will be conducted based upon the information found into your POM file. For instance, let's say you want to package your project. Before running the task, Maven will first read the packaging element of your POM to see what kind of archive is supposed to be generated for this project. Only then after knowing what you want, it will decide howto perform the operation based upon the retrieved value. As it was mentioned in the previous lesson, it is one of the main differences between Maven and the more traditional build tools.

The POM is the central piece of information of your project. It has to be shared accross the team project members and a changes history should be kept as with any source code. Therefore, the project POM file should always be kept in your SCM repository at the very root of the project. From now on, this tutorial assumes you adhere to this rule.

 
It may seem very obvious but it's worth repeating that you should make sure your POM is always up-to-date as the project evolves. The faster your team finds integration issues, the easier they will be to fix. You should tackle them as early as possible!

What is a POM made of ?

If you look at all the elements that can go in a POM file, you'll be lost. The Maven team has defined a LOT of standard information (coming mostly from Maven 1 experience) that can be put in your POM file. Honestly, I don't suggest this exciting reading to anyone unless you are specifically looking for some properties.

The POM can basically be decomposed into three different sections :