Chapter 1. Prerequisites to Using This Guide

To use the examples in this guide, you need to install and configure some supporting software, and download the code for the examples.

1.1. Install Maven

The examples used in this project require Maven v2.2.0 or later. Download Maven directly from the Apache Maven homepage, and install and configure your system as described in Procedure 1.1, “Install Maven”.

Procedure 1.1. Install Maven

  1. Verify Java Developer Kit 1.6 or above is installed. This is also a requirement for the Enterprise Platform.

    Ensure you have Java installed on your system, and have set the JAVA_HOME environment variable in your ~/.bash_profile for Linux, or in the System Properties for Windows. For more information regarding setting environment variables, refer to the Step 4 step in this procedure.
  2. Download Maven

    Note

    This step and future steps assume that you have saved Maven to the suggested location for your operating system. Maven, as any other Java application, is able to be installed in any reasonable location on your system.
    Click the compiled zip archive link, for example apache-maven-2.2.1-bin.zip
    Select a download mirror from the list.
    For Linux Users

    Save the zip archive to your home directory.

    For Windows Users

    Save the zip archive to your C:\Documents and Settings\user_name directory.

  3. Install Maven

    For Linux Users

    Extract the zip file to your home directory. If you selected the zip archive in Step 2, and do not rename the directory, the extracted directory is named apache-maven-version.

    For Windows Users

    Extract the zip archive to C:\Program Files\Apache Software Foundation. If you selected the zip archive in Step 2, and do not rename the directory, the extracted directory is named apache-maven-version.

  4. Configure Environment Variables

    For Linux Users

    Add the following lines to your ~/.bash_profile. Ensure you change the [username] to your actual username, and that the Maven directory is the actual directory name. The version number may be different than the one listed below.

    export M2_HOME=/home/[username]/apache-maven-2.2.1 export M2=$M2_HOME/bin export
       PATH=$M2:$PATH
    By including M2 at the beginning of your path, the Maven version you just installed will be the default version used. You may also want to set the path of your JAVA_HOME environment variable to the location of the JDK on your system.
    For Windows Users

    Add the M2_HOME, M2, and JAVA_HOME environment variables.

    1. Press Start+Pause|Break. The System Properties dialog box is displayed.
    2. Click the Advanced tab, then click the Environment Variables button.
    3. Under System Variables, select Path.
    4. Click Edit, and append the two Maven paths using a semi-colon to separate each entry. Quotation marks are not required around paths.
      • Add the variable M2_HOME and set the path to C:\Program Files\Apache Software Foundation\apache-maven-2.2.1.
      • Add the variable M2 and set the value to %M2_HOME%\bin.
    5. In the same dialog, create the JAVA_HOME environment variable:
      • Add the variable %JAVA_HOME% and set the value to the location of your JDK. For example C:\Program Files\Java\jdk1.6.0_02.
    6. In the same dialog, update or create the Path environment variable:
      • Add the variable %M2% to allow Maven to be executed from the command-line.
      • Add the variable %JAVA_HOME%\bin to set the path to the correct Java installation.
    7. Click OK until the System Properties dialog box closes.
  5. Implement changes to .bash_profile

    For Linux Users Only

    To update the changes made to the .bash_profile in the current terminal session, source your .bash_profile.

    [localhost]$ source ~/.bash_profile
  6. Update gnome-terminal profile

    For Linux Users Only

    Update the terminal profile to ensure that subsequent iterations of gnome-terminal (or Konsole terminal) read the new environment variables.

    1. Click EditProfiles
    2. Select Default, and click the Edit button.
    3. In the Editing Profile dialog, click the Title and Command tab.
    4. Select the Run command as login shell check box.
    5. Close all open Terminal dialog boxes.
  7. Verify the environment variable changes and Maven install

    For Linux Users

    To verify that the changes have been implemented correctly, open a terminal and execute the following commands:

    • Execute echo $M2_HOME, which should return the following result.
      [localhost]$ echo $M2_HOME /home/username/apache-maven-2.2.1
    • Execute echo $M2, which should return the following result.
      [localhost]$ echo $M2 /home/username/apache-maven-2.2.1/bin
    • Execute echo $PATH, and verify the Maven /bin directory is included.
      [localhost]$ echo $PATH /home/username/apache-maven-2.2.1/bin
    • Execute which mvn, which should display the path to the Maven executable.
      [localhost]$ which mvn ~/apache-maven-2.2.1/bin/mvn
    • Execute mvn -version, which should display the Maven version, related Java version, and operating system information.
      [localhost]$ $ mvn -version Apache Maven 2.2.1 (r801777; 2009-08-07 05:16:01+1000) Java version:
             1.6.0_0 Java home: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre Default locale: en_US, platform encoding: UTF-8 OS
             name: "Linux" version: "2.6.30.9-96.fc11.i586" arch: "i386" Family:
             "unix"
    For Windows Users

    To verify that the changes have been implemented correctly, open a terminal and execute the following command:

    • In a command prompt, execute mvn -version
      C:\> mvn -version Apache
             Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700) Java version: 1.6.0_17 Java home: C:\Sun\SDK\jdk\jre Default
             locale: en_US, platform encoding: Cp1252 OS name: "windows xp" version: "5.1" arch:
             "x86" Family: "windows"
      
You have now successfully configured Maven for use with the examples in this guide.