Sunday 7 July 2019

Introduction to POM file


What is POM?
POM is an xml file, where all the maven project structure is defined in pom.xml (Project Object model). ‘pom.xml’ file is in the base directory of the project.

Maven reads the pom file configuration, download the necessary dependencies, build the artifacts based on the configuration.

What can you specify in pom.xml?
·      Build profiles
·      Dependencies (all jar files information)
·      Developers
·      Goals
·      plugins
·      Project version
·      Mailing list

Simple pom.xml looks like 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>selflearningJava</groupId>
  <artifactId>helloworld</artifactId>
  <version>1</version>
  <name>Hello World</name>
  <description>Hello World demo maven application</description>
</project>

As you closely observe above pom.xml, you can identify the html elements which are giving information about the maven project.

Below table summarizes all the elements in above pom.xml.

Element
Description
project
it is the root element in pom.xml file. All the project specific element should be part of this element.
modelVersion
This element indicates what version of the object model this POM is using.
groupId
It specifies the unique identifier of the organization (or) group who created this project. It groups the collection of related artifacts.

For example, you can give group name as org.abc for the organization abc. The group id and artifact id combination must always be unique.
artifactId
It specifies the artifact id, usually project name.
version
Specifies the version of artifact.
name
Specify the display name used for this project
description
Gives basic description about the project.

Out of all the elements in above table <groupId>, <artifactId>, and <version> are the mandatory elements.
How the project artifact represented in maven repository?
Project represented in the form of "groupId:artifactId:version".

A typical ‘pom.xml’ file contains below categories of information.

a.   Basic project Information
b.   Build Settings
c.    Build Environment
d.   POM Relationships

Basic project Information
It contains basic information about the project like project name, license, developers and testers details who are working on this project etc.,

Build Settings
You can change the default behavior of the maven build by configuring build settings. For example, you can specify where the source code is located, where the tests are located, you can specify new plugins while executing the build etc.,

Build Environment
You can create build profiles while executing maven tasks. For example, you can create a build profile called ‘DEV_LANDSCAPE’, to deploy the artifacts into development server. You can create other build profile called ‘TEST_LANDSCAPE’ to deploy the artifacts into testing server. You can create a build profile called ‘PRODUCTION_LANDSCAPE’, to deploy the artifacts into production server.

POM Relationships
You can specify parent poms from where this pom file can inherit the settings from.
  
Reference



Previous                                                    Next                                                    Home

No comments:

Post a Comment