Maven is a software project management and comprehension tool which can enable you to manage a project's build, reporting and documentation from a central piece of information.
Installing Apache Maven on Centos 6/RHEL is relatively simple as long as you have the JDK set up correctly.
This means paying particular attention to your JAVA_HOME path/variable as Maven appends to it and uses the jre, an incorrect setting will result in Maven being unable to start properly.
JAVA_HOME should just be the top level JDK directory with or without a trailing slash ie
/usr/java/jdk1.7.0_06
Use wget if you have it installed
$ sudo yum -y install wget
$ wget http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
Or you can download directly from the the site link above
There are just 3 steps to install it as follows:
1. Unzip to /usr/local
2. Symlink to create the maven directory
3. Add the paths to /home/<user>/.bashrc
Now to install it.
$ cd /usr/local
Extract the files from the downloaded tar.gz
$ sudo tar xvf /home/<user>/apache-maven-3.0.5-bin.tar.gz
Symlink to the extracted folder and create the maven folder
$ sudo ln -s apache-maven-3.0.5/ maven
So now you have it installed at /usr/local, you need to set up paths in .bashrc
(Use your user name)
$ sudo vi /home/anton/.bashrc
Enter under your other settings
export M2_HOME=/usr/local/maven
export PATH=$M2_HOME/bin:${PATH}
Save the file and source it
$ source /home/anton/.bashrc
If you have installed Ant already also then your .bashrc might resemble as below
export JAVA_HOME="/usr/java/jdk1.7.0_06"
export JAVA_PATH="$JAVA_HOME"
export CLASSPATH=.:/usr/java/jdk1.7.0_06/lib/tools.jar
ANT_HOME="usr/share/ant"
export PATH="$PATH:$JAVA_HOME:$ANT_HOME"
export M2_HOME=/usr/local/maven
export PATH=$M2_HOME/bin:${PATH}
With the CLASSPATH added for good measure.
Now is probably a good time to test all those entries just in case, so
$ echo $JAVA_HOME
/usr/java/jdk1.7.0_06
$ echo $CLASSPATH
.:/usr/java/jdk1.7.0_06/lib/tools.jar
$ echo $ANT_HOME
/usr/share/ant
and finally check your new Maven installation
$ mvn -version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 13:51:28+0000)
Maven home: /usr/local/maven
Java version: 1.7.0_06, vendor: Oracle Corporation
Java home: /usr/java/jdk1.7.0_06/jre
Default locale: en_US, platform encoding: UTF-8
OS name: “linux”, version: “2.6.32-358.6.2.el6.i686“, arch: “i386“, family: “unix”
Test Maven
To get started or test it out first create a project folder
and move into it.
$ mkdir mavapp && cd mavapp
Start maven and issue the archetype:generate command
$ mvn archetype:generate
Maven will download some required packages and then you will be asked to choose a quickstart version number
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Enter 6 and continue, more packages will be downloaded and you will be asked to define values, my examples below, the package value will default to whichever the groupid is.
Define value for property 'groupId': : com.dom.romcom
Define value for property 'artifactId': : MavenTestApp
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': com.dom.romcom: :
After a confirmation 'Y' the project will be set up
[INFO] Parameter: groupId, Value: com.dom.romcom
[INFO] Parameter: packageName, Value: com.dom.romcom
[INFO] Parameter: package, Value: com.dom.romcom
[INFO] Parameter: artifactId, Value: MavenTestApp
[INFO] Parameter: basedir, Value: /home/anton/mavapp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/anton/mavapp/MavenTestApp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4:51.066s
[INFO] Finished at: Sun Jun 16 17:42:59 BST 2013
[INFO] Final Memory: 14M/178M
Maven also generates predefined archetypes which you can choose
for example 768 gives you a choice of Spring versions to pick in a similar fashion. Below shows the directory structure for both when done.
Inside the src folders are the main and test folders for the projects class files and junit test cases.
The above are just examples, for more info on using Maven check out the Apache Maven site.