The pom.xml is the master configuration file for a Maven project. Every project has exactly one pom.xml.
Here is what the pom.xml for the HelloWorldJARArch project looks like:
<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>org.confucius</groupId>
<artifactId>HelloWorldJARArch</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>HelloWorldJARArch</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
First, note that unlike an Ant build.xml, the pom.xml DOES NOT contain step-by-step instructions for the build.
It declares the packaging as a 'jar' - that is all Maven needs to know.
Other than that, it contains some metadata - group id, artifact id, version - the three unique coordinates of any Maven project - we will learn more about Maven co-ordinates later.
Then it contains the descriptive name of the project (you can give it any descriptive name - like, "My first Maven project") and a URL in case this project had a web page.
Then come the properties - Maven properties are value placeholder, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property.
Finally, one of the most important parts of any pom.xml -- the dependencies.
Just like Ivy, the dependencies are a list of all the external jars your project depends on. Each dependency is specified by a unique combination of groupId, artifactId and version. This unique combination is called the co-ordinates of the jar.
By default, Maven will look for dependency jars by their co-ordinates in the central Maven repository. It is possible to tell Maven to look in other repositories as well.
No comments:
Post a Comment