Maven pom.xml file

Maven pom.xml file for beginners and professionals with topics on maven example, plugin, pom, dependency, eclipse, repository, web application, eclipse example, servlet, jsp, struts, hibernate, spring etc.

Maven pom.xml file

Maven pom.xml file

POM is an acronym for Project Object Model. The pom.xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.

Maven reads the pom.xml file, then executes the goal.

Before maven 2, it was named as project.xml file. But, since maven 2 (also in maven 3), it is renamed as pom.xml.


Elements of maven pom.xml file

For creating the simple pom.xml file, you need to have following elements:

Element Description
project It is the root element of pom.xml file.
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.
File: pom.xml
  1. <project xmlns="http://maven.apache.org/POM/4.0.0"   
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   
  4. http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.   
  6.   <modelVersion>4.0.0</modelVersion>  
  7.   <groupId>com.javatpoint.application1</groupId>  
  8.   <artifactId>my-app</artifactId>  
  9.   <version>1</version>  
  10.   
  11. </project>  

Maven pom.xml file with additional elements

Here, we are going to add other elements in pom.xml file such as:

Element Description
packaging defines packaging type such as jar, war etc.
name defines name of the maven project.
url defines url of the project.
dependencies defines dependencies for this project.
dependency defines a dependency. It is used inside dependencies.
scope defines scope for this maven project. It can be compile, provided, runtime, test and system.
File: pom.xml
 
  1. <project xmlns="http://maven.apache.org/POM/4.0.0"   
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   
  4. http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.   
  6.   <modelVersion>4.0.0</modelVersion>  
  7.   
  8.   <groupId>com.tpoint.application1</groupId>  
  9.   <artifactId>my-application1</artifactId>  
  10.   <version>1.0</version>  
  11.   <packaging>jar</packaging>  
  12.   
  13.   <name>Maven Quick Start Archetype</name>  
  14.   <url>http://maven.apache.org</url>  
  15.   
  16.   <dependencies>  
  17.     <dependency>  
  18.       <groupId>junit</groupId>  
  19.       <artifactId>junit</artifactId>  
  20.       <version>4.8.2</version>  
  21.       <scope>test</scope>  
  22.     </dependency>  
  23.   </dependencies>  
  24.   
  25. </project>