Now that we have Eclipse installed, we will add Maven to our Java toolbox. Maven will allow us to manage the projects and automate their building processes. The installation will be done inside the user's home folder and afterwards we will plug it into Eclipse. The version installed is the Maven v3.0.3 and the plugin installed to integrate Maven into Eclipse is m2eclipse, provided by Sonatype.
Required software that has already been installed and configured on the system.
Required files (~/downloads)
Downloaded files required during the installation process.
Step 1 - Unpack and move to the desired location
Go to the downloads directory, extract the downloaded file apache-maven-3.0.3-bin.tar.gz, and move the generated folder to the desired location. In this case, we will move the folder inside the "Work area", under the tools folder. Also, a softlink will be created for the maven folder.
me@rarejava:~/downloads$ tar xvfz apache-maven-3.0.3-bin.tar.gz apache-maven-3.0.3/boot/plexus-classworlds-2.4.jar apache-maven-3.0.3/lib/maven-embedder-3.0.3.jar [...] apache-maven-3.0.3/lib/ apache-maven-3.0.3/lib/ext/ apache-maven-3.0.3/lib/ext/README.txt me@rarejava:~/downloads$ mkdir -p ~/lab/tools me@rarejava:~/downloads$ mv apache-maven-3.0.3 ~/lab/tools me@rarejava:~/lab/tools$ ln -s ~/lab/tools/apache-maven-3.0.3/ mavenTerminal
Step 2 - Configure environment variables
We will need to set two environment variables, MAVEN_HOME* and PATH. To set these environment variables we can edit both ~/.profile or ~/.bashrc file.
# Maven environment variables export MAVEN_HOME=$HOME/lab/tools/maven export PATH=$PATH:$MAVEN_HOME/bin~/.profile
Log out if you have edited the .profile file or close all the terminals if you have edited the .bashrc file to apply the changes. Open a terminal and execute: "mvn -version".
me@rarejava:~$ mvn --version Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100) Maven home: /home/me/lab/tools/maven Java version: 1.6.0_23, vendor: Sun Microsystems Inc. Java home: /home/me/lab/jvm/jdk1.6.0_23/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "2.6.35-27-generic", arch: "i386", family: "unix"Terminal
The output of executing the previous command should display the Maven and Java version and their installation paths, together with some information about the system. From now on, we will be able to run Maven from the command line.
*This tweet summarizes my decision about the name choosen for the Maven home environment variable.
Step 3 - Integration with Eclipse
Installing the plugin
The m2eclipse plugin itself comes with a Maven instance, but we have previously installed another Maven instance in an external folder because we will chose it as the instance to be used by Eclipse. The installation of this plugin is straight forward, so let's do it quickly, do not blink...
- On Eclipse menu select "Help > Install new software..."
- Fill the field named "Work with:" with this URL: “http://m2eclipse.sonatype.org/sites/m2e” and press enter.
- Once Eclipse has updated the list of available components choose the item listed under m2eclipse, "Maven Integration for Eclipse (Required)", and click Next.
- The “Maven Integration for Eclipse (Required)” will appear on a list of components that will be installed, click Next.
- Accept the terms of the licence agreement and click Finish to start the installation process.
Once finished, Eclipse will ask you to restart the IDE, so do it :-P
Choosing our Maven instance
Just one more thing left to finish. After restart Eclipse select the menu option "Window > Preferences", look for "Maven > Installations". There, we will add our external installation of Maven, click "Add..." and browse to ~/lab/tools/maven, click Open and this is it, where are done.
At this point, wheter we execute Maven from the command line or from inside Eclipse the same instance of Maven will be executed.
- http://maven.apache.org Concepts
- http://sonatype.com/books/maven-book/reference/installation-sect-maven-install.html Installation
- http://www.avajava.com/tutorials/lessons/... Concepts Installation
- http://m2eclipse.sonatype.org/installing-m2eclipse.html m2eclipse
- http://commons.wikimedia.org/wiki/File:Date-seller.jpg Image