Installing Maven

Before we install Maven, we need to have JDK installed. Check out the Java installation with the following command:

>javac -version

For Windows, open the command prompt, and for Linux/Mac OS, open the terminal and use the preceding command to see the version of the JDK that is installed.

If JDK is not installed, please refer to following link and install it:

http://www.oracle.com/technetwork/java/javase/index-137561.html

Once Java is in place, let's move towards Maven's installation.

Maven's installation is a simple two-step process:

  • Setting up Maven home, that is, the M2_HOME variable
  • Adding Maven home to the PATH variable

Installing Maven on Windows

The installation of Maven is just setting up Maven home in the extracted Maven folder. For ease, let's assume the maven3 folder resides in C:Program Files. Now, set Maven home with the following command in the command prompt:

set M2_HOME="c:Program Filesmaven3apache-maven-3.2.1"

Update the PATH variable as follows:

set PATH =%PATH%;%M2_HOME%in

Alternatively, the variables can be set permanently by navigating to Desktop | My Computer | Properties. Visit http://www.computerhope.com/issues/ch000549.htm for more information.

Installing Maven on Linux and Mac OS

Let's assume the maven3 folder resides in the /opt folder. As Mac OS does not have the /opt folder, let's create a folder opt in root, that is, /opt. Now, let's assume we have maven3, the extracted folder in it. Then, set the Maven home by issuing the following command via the terminal:

export  M2_HOME=/opt/maven3/apache-maven-3.2.1

Add Maven to the PATH variable as follows:

export PATH=${M2_HOME}/bin:${PATH}

To add it permanently, add it to the bash file as follows:

cd $HOME
vi .bash_profile

Add the preceding variable, that is, two lines to the file, save it, and execute the following command:

source  .bash_profile

Verifying the installation of Maven

After performing the previous steps, its time to verify the installation of Maven. To verify the installation, perform the following:

  • For Windows, open the command prompt and type the following:
    mvn -version
    
  • For Linux and Mac OS, open the terminal and type the following:
    mvn -version
    

It should show the corresponding version of Maven installed, as shown in the following screenshot:

Verifying the installation of Maven
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.74.160