Maven pom.xml Introduction

Project Object Model (pom.xml) :

POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named pom.xml.


The POM contains information about the project and various configuration detail used by Maven to build the project(s).


It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/main/test; and so on.


POM also contains the goals and plugins. While executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.


The POM contains all necessary information about a project, as well as configurations of plugins to be used during the build process.

Project Object Model (pom.xml) :

POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named pom.xml.


The POM contains information about the project and various configuration detail used by Maven to build the project(s).


It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/main/test; and so on.


POM also contains the goals and plugins. While executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.


The POM contains all necessary information about a project, as well as configurations of plugins to be used during the build process.





<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-project</artifactId>
  <version>1.0</version>
</project>

There should be a single POM file for each project.

  • All POM files require the project element and three mandatory fields: groupId, artifactId,version.
  • Projects notation in repository is groupId:artifactId:version.
  • Root element of POM.xml is project and it has three major sub-nodes :

POM Sample :

<project>   
<modelVersion>4.0.0</modelVersion>   
<groupId>org.codehaus.cargo</groupId>   
<artifactId>cargo-core-api-container</artifactId>   
<name>Cargo Core Container API</name>   
<version>0.7-SNAPSHOT</version>   
<packaging>jar</packaging>   
<dependencies/>    
<build/>
[...]



  • project :- It is the root element of project
  • modelVersion :- It is the sub element of project. It specifies the modelVersion. It should be set to 4.0.0.
  • groupId :- It is the sub element of project. It specifies the id for the project group.
  • artifactId :- It is the sub element of project. It specifies the id for the artifact (project). An artifact is something that is either produced or used by a project. Examples of artifacts produced by Maven for a project include: JARs, source and binary distributions, and WARs.
  • version:-It is the sub element of project. It specifies the version of the artifact under given group.

Note:-When no packaging is declared, Maven assumes the artifact is the default: jar.





comments powered by Disqus