Maven Environment Setup

Advertisements


Maven is Java based tool, so the very first requirement is to have JDK installed on your machine.

System Requirement

JDK1.5 or above.
Memoryno minimum requirement.
Disk Spaceno minimum requirement.
Operating Systemno minimum requirement.

Step 1 - verify Java installation on your machine

Now open console and execute the following java command.

OSTaskCommand
WindowsOpen Command Consolec:\> java -version
LinuxOpen Command Terminal$ java -version
MacOpen Terminalmachine:~ joseph$ java -version

Let's verify the output for all the operating systems:

OSOutput
Windows java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
Linux java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
Mac java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)

If you do not have Java installed, install the Java Software Development Kit (SDK) from http://www.oracle.com/technetwork/java/javase/downloads/index.html. We are assuming Java 1.6.0_21 as installed version for this tutorial.

Step 2: Set JAVA environment

Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example

OSOutput
WindowsSet the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_21
Linuxexport JAVA_HOME=/usr/local/java-current
Macexport JAVA_HOME=/Library/Java/Home

Append Java compiler location to System Path.

OSOutput
WindowsAppend the string ;C:\Program Files\Java\jdk1.6.0_21\bin to the end of the system variable, Path.
Linuxexport PATH=$PATH:$JAVA_HOME/bin/
Macnot required

Verify Java Installation using java -version command explained above.

Step 3: Download Maven archive

Download Maven 2.2.1 from http://maven.apache.org/download.html

OSArchive name
Windowsapache-maven-2.0.11-bin.zip
Linuxapache-maven-2.0.11-bin.tar.gz
Macapache-maven-2.0.11-bin.tar.gz

Step 4: Extract the Maven archive

Extract the archive, to the directory you wish to install Maven 2.2.1. The subdirectory apache-maven-2.2.1 will be created from the archive.

OSLocation (can be different based on your installation)
WindowsC:\Program Files\Apache Software Foundation\apache-maven-2.2.1
Linux /usr/local/apache-maven
Mac/usr/local/apache-maven

Step 5: Set Maven environment variables

Add M2_HOME, M2, MAVEN_OPTS to environment variables.

OSOutput
WindowsSet the environment variables using system properties.

M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1

M2=%M2_HOME%\bin

MAVEN_OPTS=-Xms256m -Xmx512m

LinuxOpen command terminal and set environment variables.

export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1

export M2=$M2_HOME/bin

export MAVEN_OPTS=-Xms256m -Xmx512m

MacOpen command terminal and set environment variables.

export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1

export M2=$M2_HOME/bin

export MAVEN_OPTS=-Xms256m -Xmx512m

Step 6: Add Maven bin directory location to system path

Now append M2 variable to System Path

OSOutput
WindowsAppend the string ;%M2% to the end of the system variable, Path.
Linuxexport PATH=$M2:$PATH
Macexport PATH=$M2:$PATH

Step 8: Verify Maven installation

Now open console, execute the following mvn command.

OSTaskCommand
WindowsOpen Command Consolec:\> mvn --version
LinuxOpen Command Terminal$ mvn --version
MacOpen Terminalmachine:~ joseph$ mvn --version

Finally, verify the output of the above commands, which should be something as follows:

OSOutput
Windows Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre
Linux Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre
Mac Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre

Congratulations! you are now all set to use Apache Maven for your projects.



Advertisements
Advertisements