In the previous post, we have seen how to create the Maven project and import that into eclipse. In this post, we will learn about one important component of Maven that is nothing but POM.Xml.
POM.xml in Maven:
- POM stands for “Project Object Model”, which is an important unit of work in Maven.
- It is a XML file, which contains information about project and configuration details which is used by Maven to build the project.
- It is created by default during creation of Maven project.
- To download jars into project, we add them in form of dependency tags by defining its groupid, artifact id,version etc.
- POM can also contain different goals and plugins to achieve some desired actions.
- In Maven 1, POM was known as project.xml. It is renamed to POM in Maven 2.
- POM resides in the current directory i.e. at project level.
- POM may keep increasing in size as the project grows but it makes developers’ jobs easier to maintain complex projects.
Project is the root element in the POM and it has 3 major sub-nodes.
|groupId||It is id or say package which exists in POM. IT is generally unique in the project. e.g. com.testing.Mobile|
|artifactId||It is basically the project name.The artifactId defines the artifact’s location within the repository.|
|version||It is the project version.It is used within an artifact’s repository to separate versions from each other. e.g. com.testing.Mobile : Model 1.0 and com.testing.Mobile : Model 1.1|
Below, we have shown a POM.xml File, which is containing the dependency for testng which is having project name testng, groupid org.testng and version 6.3.1. We can define multiple dependencies under a single <dependencies> tag.
It is also having a plugin for sure-fire report which is defined under <build> tag. In <suiteXmlFiles>, we are providing the path for testng.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<plugins> <!-- plugins in POM-->