Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Apache Maven 3

You're reading from   Mastering Apache Maven 3 Enhance developer productivity and address exact enterprise build requirements by extending Maven

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781783983865
Length 298 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (11) Chapters Close

Preface 1. Apache Maven Quick Start FREE CHAPTER 2. Demystifying Project Object Model 3. Maven Configuration 4. Build Lifecycles 5. Maven Plugins 6. Maven Assemblies 7. Maven Archetypes 8. Maven Repository Management 9. Best Practices Index

Installing Apache Maven

Installing Maven on any platform is a straightforward task. At the time of writing this book, the latest version is 3.2.3, which is available to download from http://maven.apache.org/download.cgi. This version requires JDK 1.6.0 or above. You should keep a note of the Java requirement for version 3.2.3 if you are planning to upgrade from version 3.0.0 family or 3.1.0 family. Prior to Maven 3.2.1, the only requirement was JDK 1.5.0.

Apache Maven is an extremely lightweight distribution. It does not have any hard requirements in terms of memory, disk space, or CPU. Maven is built on top of Java and will work on any operating system that runs a Java Virtual Machine (JVM).

Installing Apache Maven on Ubuntu

Installing Maven on Ubuntu just needs a single-line command. Proceed with the following steps:

  1. Run the following apt-get command in the command prompt; you need to have the sudo privileges to execute this:
    $ sudo apt-get install maven
    
  2. The installation takes a few minutes to complete. Upon the completion of the installation, you can run the following command to verify the installation:
    $ mvn -version
    
  3. You should get an output similar to the following one if Apache Maven has been installed successfully:
    $ mvn -version
    Apache Maven 3.2.3
    Maven home: /usr/share/maven
    Java version: 1.7.0_60, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-7-oracle/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.13.0-24-generic", arch: "amd64", family: "unix"
    
  4. Maven is installed under the /usr/share/maven directory. To check the directory structure behind the Maven installation directory, use the following command:
    $ ls /usr/share/maven
    bin  boot  conf  lib  man
    
  5. Maven configuration files can be found under the /etc/maven directory using the following command:
    $ ls /etc/maven
    m2.conf  settings.xml
    

If you don't want to work with the apt-get command, there is another way of installing Maven under any Unix-based operating system. We will discuss this in the next section. Since Mac OS X has a kernel built on top of the Unix kernel, installing Maven on Mac OS X would be the same as installing it on any Unix-based operating system.

Installing Apache Maven on Mac OS X

Most of the OS X distributions prior to OS X Mavericks had Apache Maven preinstalled. To verify that you've got Maven installed in your system, try out the following command:

$ mvn –version

If it does not result in a version, this means you do not have Apache Maven installed.

The following steps will guide you through the Maven installation process:

  1. First, we need to download the latest version of Maven. Throughout this book, we will use Maven 3.2.3, which is the latest version at the time of writing this book. The Maven 3.2.3 ZIP distribution can be downloaded from http://maven.apache.org/download.cgi.
  2. Unzip the downloaded ZIP file and extract it to /usr/share/java directory. You need to have the sudo privileges to execute the following command:
    $ sudo unzip  apache-maven-3.2.3-bin.zip -d /usr/share/java/
    
  3. If you already have Maven installed in your system, use the following command to unlink:
    $ sudo unlink /usr/share/maven
    
  4. Use the following command to create a symlink to the latest Maven distribution, which you just unzipped. You need to have the sudo privileges to execute the following command:
    $ sudo ln -s /usr/share/java/apache-maven-3.2.3  /usr/share/maven
    
  5. Verify the Maven installation with the following command:
    $ mvn -version
    Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T02:28:10+05:30) 
    Maven home: /usr/share/maven
    Java version: 1.6.0_65, vendor: Apple Inc.
    Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    Default locale: en_US, platform encoding: MacRoman
    OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
    

    Note

    Maven can also be installed on Mac OS X with Homebrew. Check out the video at this link, https://www.youtube.com/watch?v=xTzLGcqUf8k, which explains the installation process in detail.

Installing Apache Maven on Microsoft Windows

First, we need to download the latest version of Maven. The Apache Maven 3.2.3 ZIP distribution can be downloaded from http://maven.apache.org/download.cgi. Next, perform the following steps:

  1. Unzip the downloaded ZIP file and extract it to C:\Program Files\ASF folder.
  2. Set the M2_HOME environment variable and point it to C:\Program Files\ASF\apache-maven-3.2.3.
  3. Verify the Maven installation with the following command on the command prompt:
    mvn –version
    

    Note

    To learn how to set the environment variables on Microsoft Windows, you can refer http://www.computerhope.com/issues/ch000549.htm.

You have been reading a chapter from
Mastering Apache Maven 3
Published in: Dec 2014
Publisher:
ISBN-13: 9781783983865
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image