Maven is a popular, if not the most popular, Java build tool and dependency management framework. It is a good idea to use a build tool rather than rely on your IDE build scripts if you are planning on collaborating with others on your Java project.
You can install Maven and be rockin' in just a few steps:
1. Install Java
First you need to have the Java JDK (Java Development Kit) installed; having the JRE (Java Runtime Environment) is not enough. To check if you have the JDK installed, open a command prompt or terminal and type
javac -version. If you have a JDK installed, you will see your javac version output, eg.
javac 1.7.0_01. If you get an error that javac is not a recognized command, download and install the Java JDK.
2. Download Maven
Download Maven from a mirror off the Apache Maven website.
3. Unpack and Set System variablesWindows
- Unzip the Maven download to the folder to which you would like to install Maven, eg. "C:\Program Files\Apache Software Foundation". The subdirectory apache-maven-x.x.x will be created from the archive, where x.x.x is the version.
- Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-x.x.x (or wherever you unzipped Maven). Be sure to omit any quotation marks around the path even if it contains spaces.
- In the same dialog, add the M2 environment variable in the user variables with the value "%M2_HOME%"\bin.
- In the same dialog, update/create the Path environment variable in the user variables and prepend the value "%M2%" to add Maven available in the command line.
- In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.7.0_06 and that %JAVA_HOME%\bin is in your Path environment variable.
- Open a new command prompt (type cmd in Start menu) and run mvn --version to verify that it is correctly installed.
- Extract the distribution archive, i.e. apache-maven-x.x.x-bin.tar.gz (where x.x.x is the version) to the directory you wish to install Maven. These instructions assume you chose /usr/local/apache-maven. The subdirectory apache-maven-x.x.x will be created from the archive.
- In a command terminal, add the M2_HOME environment variable.
- Add the M2 environment variable
- Add M2 environment variable to your path.
- Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.7.0_06 and that $JAVA_HOME/bin is in your PATH environment variable.
- Run mvn --version to verify that it is correctly installed.
Stack Exchange - Getting Started With Build Tools
Apache - Maven in 5 Minutes