Pages

Maven POM


Pom File: 



POM is stands for "Project Object Model" is an XML file which contains information about the project which you want to build and configuration details used by MAVEN to build the project.

For example it define the directory structure for your source file and your class file. and also define the location where dependencies related to your project is stored.

POM also contains the goals and plugins. While executing a task or goal, Maven looks for the pom.xml in the current directory.


Some of the configuration that can be specified in the POM are following:
  • project dependencies
  • plugins
  • goals
  • build profiles
  • project version
  • developers
  • mailing list

Sample Pom

<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>practise</groupId>
    <artifactId>apachetika</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</project> 
 
There should be a single POM file for each project.

  • project – root element of every POM file.
  • modelVersion – The modelVersion element sets what version of the POM model you are using
  • groupId – The groupId element is a unique ID for an organization, or a project
  • artifactId – The artifactId element contains the name of the project you are building
  • version – The version element contains the version number of the project.
The above groupId, artifactId and version elements would result in a JAR file being built and put into the local Maven repository.

Super POM :

All POMs inherit from a parent (despite explicitly defined or not). This base POM is known as the Super POM, and contains values inherited by default.  

All Maven project POMs extend the Super POM, which defines a set of defaults shared by all projects.

Effective POM :

Maven use the effective pom (super pom + pom.xml ) to execute relevant goal.


Defining Dependency on POM file for your project : sample pom for defining dependencies

 <dependencyManagement>
  <dependencies>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.15</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-parsers</artifactId>
            <version>1.15</version>
        </dependency>
    </dependencies>     
  </dependencyManagement>

No comments:

Post a Comment