Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

Getting Started with Maven

General

Although Maven can be used integrated in your favorite IDE, its basic usage is as a commandline tool. So, go download the latest release and install it. To begin using Maven, you have to download and install it.

Begin here: http://maven.apache.org/download.html

I started with Maven 2.0.4. Download the binary distribution that suits your operating system, e.g. tar.gz (linux), or zip (windows). Unzip the contents to directory that is accessible to your user. My installation is at /home/piratepete/maven-2.0.4 .

However, we can't use Maven just yet. Maven requires two environement variables: M2_HOME, and JAVA_HOME. M2_HOME refers to the directory where you unpacked your Maven, while JAVA_HOME, refers to your JDK directory.

For Unix users: 

and

For Windows users:

and

Environment variables are handy e.g. if you change things a lot. After you install Maven you'll need to set your PATH to the $M2_HOME/bin directory. Although modifying the PATH environmental variable is not required, it is highly recommended so thatyou can use Maven outside its installation directory.

For Unix users: 

PATH=$M2_HOME/bin:$PATH

For Windows users:

Now open a terminal or cmd window. Type the following and you'll see something like:

piratepete@piratepete-laptop:~$ mvn --version
Maven version: 2.0.4

or

Maven for Make and GNU Autotools users

Please Contribute

Icon

This section is incomplete. If you have experience with Make, Maven, and/or the GNU Autotools, please add any information here that you think might be useful to new Maven users.

Since both Maven and the GNU Autotools are involved with configuring and executing a software build, there is much overlap in their capabilities and the scenarios in which they are used. However, there are also some significant differences. It is hoped that this section will help bridge the conceptual gap between these tools.

From this point on, our discussion of Make will be implied by discussion of the GNU Autotools. We do this in part to simplify (in the future we have separate Make and GNU Autotools sections of this page), and in part becuase the conventions used by hand-rolled Makefiles are generally a subset of the requirements documented in the GNU Coding Standards.

Over the years a number of conventions have come into widespread use for expected targets and behaviors in Makefiles. The "best practices" in this area are documented in the GNU Coding Standards (in particular, see the "Makefile Conventions" subsection of "The Release Process" section.

In Make, the developer typically supplies (at least) the following targets: all, clean, and install, and often times check (or test), as well.

In Maven, the "targets" are really the names of a phase of one of the maven lifecycles. There are three Maven lifecycles: default, clean, and site.

When a user invokes a Make target (or targets), Make uses the timestamps of dependent artifacts to decide which previous targets need to be rebuilt prior to building the requested target(s). In maven, the user invokes a phase name (or names), and Maven runs all previous build phases that belong to the same lifecycle as the invoked phase(s).

A typical Make invocation might look like this:

$ make clean && make all

A typical Maven-2.x invocation might look like this:

$ mvn clean install

Users and developers familiar with the conventional Make target install might cringe at that mvn invocation, but the install phase in Maven is not at all like the target by that name typically found in a Makefile. In fact, Maven does not have a build phase that maps to the functionality typically performed by make install (and I have never seen such functionality kludged into a Maven build). This is one of the areas where the intended audiences of the tool diverge; make install is (typically, but not necessarily) intended for sysadmins actually installing software on a system for use by end-users, whereas mvn install is typically done by a developer working in his home directory, and simply copies the current build artifact beneath a special directory (${HOME}/.m2/repsoitory/...) that will be queried by other Maven builds that declare a dependency on the artifact.

  • No labels