What is POM (Project Object Model) And Pom.Xml in Maven
This Tutorial Explains What is POM (Project Object Model) and pom.xml in Maven along with pom.xml Example.
Project Object Model or POM is the basic part of the Maven functionality. This is an XML file that has information on the dependencies, configurations, and other important information about the project. Maven goes through this information and then performs the designated task.
Given below is the list of information that the pom.xml file contains:
1.Project dependencies 2.Plugins 3.Goals for the project 4.Profiles 5.Version 6.Description of the project 7.Distribution list 8.Developers 9.Directory of the source folder 10.Directory of build 11.Directory of the test source
There is a parent-child relationship between the POM files in a project. The pom file we developed for our specific project inherits the properties of the super pom.
The minimal pom configuration refers to the groupId, artifactId, and version defined for our project. It is easy and simple to describe minimal pom configuration.
Given below is a code snippet for a minimal pom configuration.
<project> <modelVersion> 1.0 </modelVersion> <groupId > com.TestProject </groupId> <artifactId > MavenJavaProject </artifactId> <version > 3.0 </version> </project>
In case there are no minimal configurations defined, then Maven shall fetch the necessary information from the super pom.xml file.
The default pom configuration solely depends on the archtype. For example in a Maven project that has quickstart archtype, by default, has a pom file shown 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion> 3.8.0 </modelVersion> <groupId> KeywordFramework </groupId> <artifactId> Excel </artifactId> <version> 0.0.1-S </version> <dependencies> < !-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId> org.apache.poi </groupId> <artifactId> poi-ooxml </artifactId> <version> 4.1.1 </version> </dependency> < !-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId> org.apache.poi </groupId> <artifactId> poi </artifactId> <version> 4.1.1 </version> </dependency> </dependencies> </project>
The pom file we use is a fusion of the pom file of the project, super pom file, and parent pom file (if present). This is called an effective pom file.
In order to generate an effective pom file, navigate to the project folder, and execute the following command:
Key Features Of pom.xml File In Maven
- Name: As the name suggests, it describes the name of the project. There is a difference between the name and artifactId. While artifactId identifies a project uniquely and is considered as a basic step. Name is just a readable name and is not considered as a mandatory step for identifying a project in Maven.
- URL: This describes the url of the project. Similar to the name, url is not a mandatory tag. It mostly provides additional data about the project.
- Packaging: This details the package type in the form of jars or war.
- Dependencies: They describe the dependencies of the project. Each dependency is a part of the dependencies tag. Dependencies tag contain multiple dependencies.
- Dependency: They describe individual dependency information like the groupId, artifactId, and version.
- Scope: They outlines the periphery of the project. It can have the following values like import, system, test, runtime, provided, and compile.
- Project: This is the root tag for the pom.xml file.
- Model version: This is a part of the project tag. It defines the model version and for Maven 2 and 3, its value is set to 4.0.0.
Given below is a sample xml code with the above POM features:
<project> <modelVersion> 3.7.0 </modelVersion> <groupId> com.softwarehelp </groupId> <artifactId> Selenium Maven </artifactId> <version>1.0- S </version> <packaging> war </packaging> <name> Maven Tutorial Series </name> <url>http://maven.apacheseries.org</url> <dependencies> <groupId> org.apache.poi </groupId> <artifactId> poi </artifactId> <version> 4.1.1 </version> </dependencies> </project>
The other key features of the pom.xml file like groupId, artifactId, and version have been explained in detail in the introductory tutorial on Maven.