Project Object Model – What is POM?

pom

What is POM
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this are the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/main/test; and so on.
The POM was renamed from project.xml in Maven 1 to pom.xml in Maven 2. When 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 the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.

Super POM
The Super POM is Maven’s default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects. The snippet below is the Super POM for Maven 2.0.x.
The snippet below is the Super POM for Maven 2.0.x.
4.0.0
Maven Default Project

central
Maven Repository Switchboard
default
http://repo1.maven.org/maven2

false

central
Maven Plugin Repository
http://repo1.maven.org/maven2
default

false

never

target
target/classes
${artifactId}-${version}
target/test-classes
src/main/java
src/main/scripts
src/test/java

src/main/resources

src/test/resources

target/site
release-profile

performRelease

true
org.apache.maven.plugins
maven-source-plugin

attach-sources

jar

true
org.apache.maven.plugins
maven-javadoc-plugin

attach-javadocs

jar

true
org.apache.maven.plugins
maven-deploy-plugin

true

 

 

Minimal POM
The minimum requirement for a POM are the following:

  • project root
  • modelVersion – should be set to 4.0.0
  • groupId – the id of the project’s group.
  • artifactId – the id of the artifact (project)
  • version – the version of the artifact under the specified group

Here’s an example:


  4.0.0
  com.mycompany.app
  my-app
  1

A POM requires that its groupId, artifactId, and version be configured. These three values form the project’s fully qualified artifact name. This is in the form of ::. As for the example above, its fully qualified artifact name is “com.mycompany.app:my-app:1”.
Every Maven project has a packaging type. If it is not specified in the POM, then the default value “jar” would be used.
Project inheritance
Elements in the POM that are merged are the following:

  • dependencies
  • developers and contributors
  • plugin lists (including reports)
  • plugin executions with matching ids
  • plugin configuration
  • resources

The Super POM is one example of project inheritance, however you can also introduce your own parent POMs by specifying the parent element in the POM, as demonstrated in the following examples.

Tagged : / / / / / / / / / / / /

Properties in Maven – List of Maven Properties

properties-in-maven

Intro
It is a collection of things found in the offcial maven documentation and postings to the maven user mailing list.
Build in properties

  • ${basedir} represents the directory containing pom.xml
  • ${version} equivalent to ${project.version} or ${pom.version}

Pom/Project properties
All elements in the pom.xml, can be referenced with the project. prefix or using pom. as prefix. This list is just an example of some commonly used elements.

  • ${project.build.directory} results in the path to your “target” dir, this is the same as ${pom.project.build.directory}
  • ${project.build.outputDirectory} results in the path to your “target/classes” dir
  • ${project.name} or ${pom.name} refers to the name of the project.
  • ${project.version} or ${pom.version} refers to the version of the project.
  • ${project.build.finalName} refers to the final name of the file created when the built project is packaged

Local user settings
Similarly, values in the user’s settings.xml can be referenced using property names with settings. prefix.

  • ${settings.localRepository} refers to the path of the user’s local repository.
  • ${maven.repo.local} also works for backward compatibility with maven1 ??

Environment variables
Environment variables can be referenced using the env prefix

  • ${env.M2_HOME} returns the Maven2 installation path.
  • ${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
    ${java.home}../bin/java.exe

Java system properties
All Java System Properties defined by the JVM.
Custom properties in the POM
User defined properties in the pom.xml.

hello

  • ${my.filter.value} will result in hello if you inserted the above XML fragment in your pom.xml

Parent Project variables
How can parent project variables be accessed?
You can use the prefix: ${project.parent}.
A good way to determine possible variables is to have a look directly at the API. I’m currently using Maven 2.2.1, and to access the Parent you can use ${project.parent}. This will return an org.apache.maven.project.MavenProject instance.
To access the parent version: ${parent.version}.
Reflection Properties
The pattern ${someX.someY.someZ} can simply sometimes mean getSomeX().getSomeY().getSomeZ(). Thus, properties such as ${project.build.directory} is translated to getProject().getBuild().getDirectory().
List of Maven Properties

project (from [1])
o project.distributionManagementArtifactRepository
o project.artifact
o project.parent
o project.file
o project.artifacts
o project.parentArtifact
o project.pluginArtifacts
o project.remoteArtifactRepositories
o project.pluginArtifactRepositories
o project.attachedArtifact
* settings (from [2])
o settings.offilne
o settings.interactive
* rootless (from [3])
o localRepository
o reactorProjects
* java properties (from [4])
o java.version
o java.vendor
o java.vendor.url
o java.home
o java.vm.specification.version
o java.vm.specification.vendor
o java.vm.specification.name
o java.vm.version
o java.vm.vendor
o java.vm.name
o java.specification.version
o java.specification.vendor
o java.specification.name
o java.class.version
o java.class.path
o java.library.path
o java.io.tmpdir
o java.compiler
o java.ext.dirs
o os.name
o os.arch
o os.version
o file.separator
o path.separator
o line.separator
o user.name
o user.home
o user.dir

 

Tagged : / / / / / / / / / / / / /