Tutorialspoint examples

Learn java tutorial with examples for beginners online

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:

Element Description
project This is the root element of pom.xml file.
modelVersion This is the sub element of project which specifies the modelVersion. Model version should be 4.0.0.
groupId This is the sub element of project which specifies the id for the project group.
artifactId This 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.
version This is the sub element of project which specifies the version of the project.
packaging It is used to define the packaging type such as jar, war etc.
name It is used to define the name of the maven project.
url It is used to define the url of the project.
dependencies It is used to define the dependencies for this project.
dependency It is used to define a dependency. It is used inside dependencies element.
scope It 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.tutorialspointexamples.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>


Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status