- 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
Maven is a Java tool, so you must have Java installed in order to proceed.
Download Maven Once downloaded extract zip or tat.gz file to a suitable location
- 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
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
- 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.
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.