EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Maven Tutorial Maven POM File
Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML

Maven POM File

By Priya PedamkarPriya Pedamkar

maven pom file

Introduction to Maven POM File

POM stands for Project Object Model this file contains the project information and configuration details for Maven to build the project. It contains information such as dependencies, source directory, a build directory, plugins, goals, etc.Maven reads the pom.xml file and executes the desired goal .older version of Maven 2 this file was named as project.xml, for the latest version since Maven 2 this file was renamed as POM.XML.

POM.XML stores some additional information such as project version, mailing lists, description. When maven is executing goals and tasks maven searches for POM.XML in the current directory. It reads configuration from pom file and executes the desired goal. pom is a fundamental unit file to work in maven.

  • Super POM is mavens default POM.XML file.
  • It contains some default values for most of the projects.

Basic Structure of POM.XML

The basic structure of pom.xml are given below:

<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.educba.examples</groupId>
<artifactId>example4</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Basic Key Elements Pom.Xml Contains

Basic key elements pom.xml contains are given below:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,560 ratings)
Tag Name Description
Project This is the root element of every POM.XML file and this is top level element.
modelVersion Sub element of project tag. Indicates the version model in which the current pom.xml is using. Version model changes in very infrequently .in some cases it’s mandatory to ensure stability.
groupId Sub element of the project tag, indicates a unique identifier of a group the project is created. Typically fully qualified domain name.
artifactId This element indicates a unique base name-primary artifact generated by a particular project.
Version This element specifies the version for the artifact under the given group.
packaging This packaging element indicates packages type to be used by this artifact i.e. JAR, WAR, EAR.
Name This element is used to define the name for the project, often used maven generated documentation.
URL This element defines the URL of the project.
description This element provides a basic description of the project.
Dependencies This element is used to define dependencies in the project.
Dependency Sub element of dependencies, used to provide specific dependency.
Scope This element defines the scope of the maven project.

The following figure depicts the Graphical representation use of pom.xml in Maven.

Maven POM File-1.2

Examples of Maven POM File

Examples of maven pom file are given below:

1. Super POM

This POM file is Mavens default POM file, all POM files extend this super POM files created in the project. Configuration specified in super POM files are inherited.

<project>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>/Maven_projects/src/target</directory>
<outputDirectory>/Maven_project/src/java/classes</outputDirectory>
<finalName>Examplejar<finalName>
<testOutputDirectory>/Maven_project/src/test/java</testOutputDirectory>
<sourceDirectory>/Maven_projects/src/main/java</sourceDirectory>
<scriptSourceDirectory>/Maven_projects/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>/Maven_projects/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>/Maven_projects/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>/Maven_projects/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>antrun-plugin</artifactId>
<version>1.4</version>
</plugin>
<plugin>
<artifactId>maven-plugin-assemble</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>dependency-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>release-plugin</artifactId>
<version>2.5.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<outputDirectory>/Maven_project/src/site</outputDirectory>
</reporting>
<profiles>
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

To look out the default configuration of POM.XML file execute the following command.

  • Open command console => go to directory containing pom.xml => and execute command.
  • In our example, pom.xml exist in D:\Maven\Maven_projects.
  • D:\Maven\Maven_projects>mvn help:effective-pom.

help: effective-pom this command effective POM as XML for the build process.

This command produces the following output.

Maven POM File-1.1

2. Minimal POM

Some of the important requirements for l pom files are given below.

  • Project root i.e. <project>
  • Model version i.e. <modelVersion>
  • Group ID i.e. <groupId>
  • Artifact Id i.e. <artifactId>
  • Version i.e. <version>

Consider the following POM file.

<Project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.educba.example</groupId>
<artifactId>example4</artifactId>
<version>1</version>
</project>

In pom file compulsorily groupId, artifactId, version should be configured. These three values depict the fully qualified artifact name of the project.in case the configuration details are not specified maven uses default configuration specified in the super pom file. For example, if packaging type is not specified then default packaging type ‘JAR’ is used.

Note: On the Project Inheritance (with respect to POM files).

Maven allows two POM files Parent pom and Child pom files. While inheriting from parent pom child pom file inherits or that are merged following properties. And these properties are also contained in parent pom file.

  • Plugin configuration.
  • Dependencies.
  • Resources.
  • Plugin lists.
  • Plugin execution Ids.

3. Parent POM

Super pom is one of the examples for the parent pom file which is written above. Inheritance is achieved through a super pom file.

For Parent and child pom Maven checks two properties.

  • POM file in Project root directory.
  • Reference from child POM file which contains the same coordinates stated in parent POM.
Note: Example for Maven parent POM please refer Super POM.

An important reason to use parent POM file is to have a central place to store information about artifacts, compiler settings, etc. and these are shared in all modules.

4. Child POM

Child POM file refer the parent POM file using the <parent> tag .groupId, artifactId,version attributes are compulsory in child pom file. Child POM file inherits all dependencies and properties from the parent POM file. additionally, It also inherits subprojects dependencies.

Consider following pom file.

<project>
<parent>
<groupId>com.educba.examples</groupId>
<artifactId>example4</artifactId>
<version>1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.educba.examples</groupId>
<artifactId>module_1</artifactId>
<version>1</version>
</project>

Conclusion

Maven provides one of the most important benefits is handling project relationships inheritance and dependencies. Dependency management in previous days was the most complicated mess for handling complex projects maven solves these problems through dependency management through repositories .most important feature of the POM file is its dependency List. The POM file programmer can add new dependency easily and quickly. Using POM hierarchy duplication can be avoided. POM inheritance helps in less time consumption and reduces the complexity of multiple dependency declaration. The quick project set up is achieved through POM files no build.xml compared to other tools. In some cases POM.XML becomes very large for complex projects.in large projects sometimes it’s very difficult to maintain the jars in a repository and that makes use of several versions of jar files.

Recommended Articles

This is a guide to Maven POM File. Here we discuss the Introduction and the basic structure of pom.xml along with Examples. You may also have a look at the following articles to learn more –

  1. What is Maven Plugins?
  2. Maven Life Cycle
  3. Maven Exclude Dependency
  4. Maven Deploy
Popular Course in this category
Maven Training (4 Courses, 6 Projects)
  4 Online Courses |  6 Hands-on Project |  26+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more