Table of Contents
Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software:
- It describes how software is built.
- It describes its dependencies.
The following tutorial shows how to download, install and configure Apache Maven 3.2.2 on Windows.
Maven Prerequisites #
As Maven needs Java in order to work, make sure that a Java runtime environment (JRE) is installed and configured on your system.
Maven 3.2 requires JDK 1.6 or above to execute.
In order to check if Java is available on your system, open a command prompt and execute the following statement.
If a Java Runtime Environment (JRE) is correctly installed and configured the version will be printed as shown below.
Maven Download & Install #
Here is the direct link to download the Maven 3.2.2 binary ZIP for Windows 32 or 64 bit.
Extract the binaries archive downloaded in the previous step. The extracted root directory should contain a number of files and subdirectories as shown below.
In this example the install location is
'C:\tools\apache-maven-3.2.2'. From now on we will refer to this directory as:
Maven Configuration #
Next we need to setup a
'M2_HOME' environment variable that will point to the installed Maven runtime. In addition, if we want to run Maven from a command prompt, we need to configure the
'PATH' environment variable to contain the Maven bin directory.
When using Windows the above parameters can be configured on the Environment Variables panel. Click on the
Windows Start button and enter
env without quotes as shown below.
Environment variables can be set at account level or at system level. For this example click on
Edit environment variables for your account and following panel should appear.
Click on the
New button and enter
M2_HOME as variable name and the
[maven_install_dir] as variable value. In this tutorial the installation directory is
OK to to save.
Note that “M2_HOME” is used for Maven 2 and later. “MAVEN_HOME” is for Maven 1.
'PATH' entry and click on the
Edit button. Add
;%M2_HOME%\bin; at the end of the variable value and click
OK to save.
Note that in case a
'PATH'variable does not exist you can create it and use
%M2_HOME%\bin;as the variable value.
The result should be as shown below. Click
OK to close the Environment Variables panel.
In order to test the above configuration, open a command prompt by clicking on the
Windows Start button and typing
cmd followed by pressing
ENTER. A new command prompt should open in which the following command can be entered to verify the installed Maven version:
The result should be that the Maven version is printed as shown below.
Maven Usage #
Let’s finish the tutorial by creating a basic Maven HelloWorld project.
Open a command prompt and navigate to the directory in which you want to create the project. In the example below we will use
Next enter following Maven command and press
mvn archetype:generate -DgroupId=com.codenotfound -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Maven will start looking for the needed dependencies in order to create the project which is based on the
'maven-archetype-quickstart' archetype (= a Maven project templating toolkit). If needed, dependencies are downloaded to the local repository. Once all dependencies are resolved, the project is created and a
BUILD SUCCESS statement is shown.
Feel free to browse the created
hello-world directory. At the root you should be able to find the
pom.xml, which is the XML representation of the Maven project.
This concludes the setting up and configuring Maven 3.2.
If you found this post helpful or have any questions or remarks, please leave a comment.