Maven
  • Maven is a build automation tool used primarily for Java projects. Consider a project consisting of 100s and 1000s of Java file.
  • need to compile each and every .java file for .jar packing.
  • Similarly in case of .ear or .war file we need to add all the dependencies needed along with .jar files.
  • You can see compiling and adding dependencies for 100s of files is a serious task. This is place where maven comes for rescue.
  • Just instruct maven (using pom.xml) what to do and it will do all stuffs for you in real time.

For eg : Compiling all Java files, adding dependencies etc

Prerequisites

Maven is a Java tool, so you must have Java installed in order to proceed.

Getting Maven

Download Maven Once downloaded extract zip or tat.gz file to a suitable location

Windows Machine:
  • To run maven from command line in Windows you should have properly set JAVA_HOME, MAVEN_HOME & PATH environment variables.
  • Right Click My Computer => Properties => Advance Setting => Environment Variables
  • You can also use win+pause/break
  • Dialog will open up. Add new System Variable

Variable Name => MAVEN_HOME
Variable value => full path of your Apache Maven Binary

  • Update PATH

In Variable value => add Apache Maven’s bin path

Check for JAVA installation
  • Press win + R and type cmd to open command prompt.
  • Type java -version
  • If you get location for your Java. Your JAVA_HOME variable is pointing to correct file if not follow same steps as done for maven. Open command Prompt and type mvn -version.
  • If every thing is OK you will see
Apache Maven 3.0.5 (sdfsfserw5r453gdfgd; 2013-02-19 14:51:28+0100)
Maven home: D:\apache-maven-3.0.5\bin\..
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_25\jre
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Mac Machine :
  • Download the Maven, for example apache-maven-2.1.1-bin.tar.gz
  • Open terminal and Extracts it
    tar -xvf apache-maven-2.1.1-bin.tar.gz
  • Update ~/. bash_profile. Create this file if doesn’t exist. Add variable details
    export M2_HOME=/Users/abc/apache-maven-2.1.1
    export PATH=$PATH:$M2_HOME/bin
  • Once done press ESC => throw you back to command Mode.
  • Press :wq to save and quit.
  • Press : x exit without saving.
  • Restart the terminal. Test it.
    $mvn -version
Linux Machine (Ubuntu 16.04)
  • Download Maven binary either directly or using wget.
  • Extract downloaded file to a location let’s say Documents
  • Now we need to editĀ mavenenv.sh and tell system where is maven src code.
  • Add M2_HOME and PATH.
  • Save and Exit.
  • Sometimes you might need to update permission as well.
  • Reopen terminal and try mvn -version
  • If it doesn’t work. Just log off and Login again. AsĀ mavenenv.sh is refreshed on Login.
wget "http://www-us.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.2-bin.tar.gz"
tar -xvf Downloads/apache-maven-3.5.2-bin.tar.gz -C Documents/
sudo nano /etc/profile.d/mavenenv.sh

//Add lines in file:

	export M2_HOME=/home/user/Documents/apache-maven-3.5.2
	export PATH=${M2_HOME}/bin:${PATH}
	
//Save and exit

sudo chmod +x /etc/profile.d/mavenenv.sh

// check
mvn -version
Categories: MAVEN

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.