Javatpoint Logo

91-9990449935

 0120-4256464

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:

ElementDescription
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.
artifactIdIt 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.
versionIt is the sub element of project. It specifies the version of the artifact under given group.
File: pom.xml
<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>com.javatpoint.application1</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>

</project>

Maven pom.xml file with additional elements

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

ElementDescription
packaging defines packaging type such as jar, war etc.
name defines name of the maven project.
url defines url of the project.
dependenciesdefines dependencies for this project.
dependencydefines a dependency. It is used inside dependencies.
scopedefines scope for this maven project. It can be compile, provided, runtime, test and system.
File: pom.xml
<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>com.javatpoint.application1</groupId>
  <artifactId>my-application1</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

</project>