maven pom xml file

POM File:

POM refers to Project Object Model. It is an XML file which contains the information about the project and various configuration detail used by Maven to build the project like build directory, source directory, dependencies, test source directory, plugin, goals etc. The POM file should be in the project’s root directory.

  • Maven reads the pom.xml file.
  • Downloads dependencies into local repository.
  • Execute life cycles, build phases and goals.
  • Execute plugins.

Commonly used elements of maven pom.xml file:

ElementDescription
projectThis is the root element of pom.xml file.
modelVersionThis is the sub element of project which specifies the modelVersion. Model version should be 4.0.0.
groupIdThis is the sub element of project which specifies the id for the project group.
artifactIdThis is the sub element of project which specifies the id for the project. This is generally refers to the name of the project. The artifact ID is also used as part of the name of the JAR, WAR or EAR file produced when building the project.
versionThis is the sub element of project which specifies the version of the project.
packagingIt is used to define the packaging type such as jar, war etc.
nameIt is used to define the name of the maven project.
urlIt is used to define the url of the project.
dependenciesIt is used to define the dependencies for this project.
dependencyIt is used to define a dependency. It is used inside dependencies element.
scopeIt is used to define the scope for this maven project. It can be compile, provided, runtime, test and system.

Note: Project, modelVersion, groupId, artifactId and version are the required fields for pom.xml.

Pom.xml Example:

<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.w3spoint.application1</groupId>  
  <artifactId>test-application1</artifactId>  
  <version>1.0</version>  
  <packaging>jar</packaging>  
 
  <name>Maven First Application</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>


Please Share