Maven basics

I. Project Object Model

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.

For examples 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.

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

It reads the POM, gets the needed configuration information, and 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.


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

Here’s an example:


II. Repository

Another concept in Maven is that of a repository. The
repository holds the artifacts on which your project
depends. There are two kinds of repository: local and
remote. Both of them can be declaratively set. Unless
specified otherwise, the local repository is created in a
special directory called “.m2/repository”. In Windows, this
directory is created in C:\Documents and Settings\Administrator. For example, if your project
depends on commons-logging version 1.0.4, you can
specify the dependency in pom.xml and when maven is
executed, it will copy the appropriate commons-logging
jar file from the remote repository to the local repository
and then use it to build your project’s artifact like JARs,
WARs, EARs etc.
August 2007 | Java Jazz Up | 19
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40            Download PDF