Maven - Maven POM - maven tutorial
maven tutorial tags : apache maven , maven repository , maven central
What is POM in Maven ?
- POM stands for Project Object Model.
- It is fundamental Unit of Work in Maven.
- POM is an XML file.
- It always resides in the base directory of the project as pom.xml.
- The POM contains information about the project and various configuration detail used by Maven to build the project(s).
- POM also contains the goals and plugins.
- While executing a task or goal, Maven looks for the POM in the current directory.
- It reads the POM, gets the needed configuration information, then executes the goal.
- Some of the configuration that can be specified in the POM are following:
- project dependencies
- plugins
- goals
- build profiles
- project version
- developers
- mailing list
- Before creating a POM, we should first decide the project group (groupId), its name(artifactId) and its version as these attributes help in uniquely identifying the project in repository.
learn maven tutorial - apache maven - maven architecture - pom file - Apache Maven example programs
Learn Maven Tutorial - Maven POM - Maven Example
Sample Code:
- It should be noted that there should be a single POM file for each project.
- All POM files require the project element and three mandatory fields: groupId, artifactId,version.
- Projects notation in repository is groupId:artifactId:version.
- Root element of POM.xml is project and it has three major sub-nodes :
Node | Description |
---|---|
groupId | This is an Id of project's group. This is generally unique amongst an organization or a project. For example, a banking group com.company.bank has all bank related projects. |
artifactId | This is an Id of the project.This is generally name of the project. For example, consumer-banking. Along with the groupId, the artifactId defines the artifact's location within the repository. |
version | This is the version of the project.Along with the groupId, It is used within an artifact's repository to separate versions from each other. For example:
com.company.bank:consumer-banking:1.0 com.company.bank:consumer-banking:1.1. |
Learn Maven Tutorial - Maven POM - Maven Example
Super POM
- All POMs inherit from a parent (despite explicitly defined or not).
- POM is known as the Super POM, and contains values inherited by default.
- Maven use the effective pom (configuration from super pom plus project configuration) to execute relevant goal.
- POM helps developer to specify minimum configuration detail in his/her pom.xml.
- Although configurations can be overridden easily.
- An easy way to look at the default configurations of the super POM is by running the following command: mvn help:effective-pom
- Create a pom.xml in any directory on your computer.Use the content of above mentioned example pom.
- In example below, We've created a pom.xml in C:\MVN\project folder.
- Now open command console, go the folder containing pom.xml and execute the following mvn command.
- Maven will start processing and display the effective-pom.
- Effective POM displayed as result in console, after inheritance, interpolation, and profiles are applied.
maven tutorial tags : apache maven , maven repository , maven central
Sample Code
POM important attributes :
learn maven tutorial - POM important attributes - maven example programs
POM Sample attributes :
learn maven tutorial - POM Sample attributes - maven example programs
- In above pom.xml , the default project source folders structure,output directory, plug-ins required, repositories, reporting directory are seen, which Maven will be using while executing the desired goals.
- Maven pom.xml is also not required to be written manually.
- Maven provides numerous archetype plugins to create projects which in order create the project structure and pom.xml