Maven is a great tool for managing your projects. A lot of the documentation seems to jump into the middle and assume you already know what to do. This page does a step-by-step tutorial about setting up and running Maven.
Downloading
Download the latest version of Maven from the Apache Maven Download site. As of this writing the current version 2.0.9.
Installation
Once you download the file, extract it to a directory where you want it to be installed. The extracted tar archive will create a directory apache-maven-2.x.y under the directory you extract it from. You can download three different versions of the compressed archive: One that contains a tar file compressed with bzip2, one that contains a tar file compressed with gzip, and one that is compressed in the format of WinZip. On a Unix-like system (or Cygwin) you can download the version that you have the extract program for. On Windows you'll have to download the zip version, unless you have Cygwin installed.
Extracting the Archive File
The commands for each of three archive files are shown below:
bzip2 -dc apache-maven-2.0.9-bin.tar.bz2 | tar -xvf -
gzip -dc apache-maven-2.0.9-bin.tar.gz| tar -xvf -
unzip apache-maven-2.0.9-bin.zip
In each case the directory apache-maven-2.0.9 will be created containing the extracted archive.
Environment Variables
To use Maven you'll need to add it to your path and define the variable MVN_HOME to be the directory you installed Maven to. On my system I installed Maven to /usr/local/apache-mvn-2.0.9.
In my .profile I defined:
export MVN_PATH=/usr/local/apache-mvn-2.0.9
export PATH=$MVN_HOME/bin:$PATH
Creating a Project from Scratch
The easiest way to create a project from scratch is to use the Maven archetype plug-in, which is installed with Maven. In Maven archetypes are project templates that can be used to generate a project in a pre-specified format. The Maven archetype plug-in has several options, but for now we'll concentrate on the one that can generate a project from several different templates (or archetypes). This option is the archetype:generate option. To run it type:
mvn archetype:generate
The archetype:generate command will display a list of project archetypes. When I ran it archetype:generate showed a list of 44 project archetypes, including several to create Spring, Tapestry, Struts, or JSF projects, as well as projects to create Maven plug-ins, Jira plug-ins, web applications, and Java projects. The default archetype is the quickstart archetype which creates a Java SE project in the standard Maven directory layout under the current directory.
Creating a Project with the Quickstart Archetype
The quickstart archetype will ask the following questions (Define value for version: defaults to 1.0-SNAPSHOT, which will accept by pressing enter at the version prompt):
Define value for groupId: : com.example.proj-name
Define value for artifactId: : quicky
Define value for version: 1.0-SNAPSHOT: :
Define value for package: : jar
It will then display your answers and ask you to confirm them as shown below. The last line has 'Y: :'. This is the prompt for you to accept your entries. You can type Y (or just press enter) to confirm or just press the enter key, since the default answer is Y, and your project will be created.
Confirm properties configuration:
groupId: com.example.proj-name
artifactId: quicky
version: 1.0-SNAPSHOT
package: jar
Y: : y





