Friday, July 8, 2016

Maven for beginners : part 1

Introduction 
All build systems are essentially the same. All they have done is same tasks again and again.

  • compile source code 
  • copy recourses 
  • compile and run tests
  • package project
  • deploy project
  • cleanup
Maven is a software management and comprehension tool based on the concept of Project Object Model (POM). It is primarily used for java project but not only that but also it can manage projects on c#, Ruby, Scala and other languages. Maven is intended to make day today work of java developers easier.

Project Object Model (POM)


POM is a XML file that contains information about project and configuration details used by maven to build the project. It describe the project name, version, Artifact type, source code locations, dependencies, plugins etc.

Install and setup Maven  

Make sure that JDK is installed and JAVA_HOME variable is added as windows system variables. 

  • Download maven
You can download maven using  https://maven.apache.org/download.cgi  link. In this tutorial I have used apache-maven-3.3.9 . And extract it to C directory. ( This is for simplicity you can extract it any where you want )

  • Set environment variables for maven

  1. go to system properties -> Environment variables  
























2. Add M2_HOME and MAVEN_HOME user variables





3. Append to System path variable
























  • Check whether maven install correctly
open command prompt and enter mvn -version If you install correctly it will give window like below.  


Create First Maven Project

For this tutorial I have created folder called "maven-test-project". Go to that folder and open command prompt inside it.( press shift and right click inside folder >> inside menu you will see "open command window here" click that ).

now type mvn archetype:generate  
P.S. :make sure that you are connected to internet 



Then it will be automatically download maven archetype plugin when you are required in your first maven project. This is happen only for first time.


 After some time you will see a window like above. Those numbers indicate various archetypes which you are choose from. In default it gives archetype of maven hello world program.This number can be different in your case. Now I pressed enter to make default  maven hello world program.

now it will give you options like below.



since archetypes are the templates, they are evolve in time. Thus They have their own versions. For this tutorial I am going to choose option 6 ( latest version ). press enter for option 6.   

In next step it will be ask to provide group id 


Group id is unique among organization or project. In this case I use " com.logicx ".
Next it will ask artifactId



ArtifactId is the project name In this case I use "maven-test-project"
Next it will ask version 




SNAPSHOT means this is development version not a release version. In this case I give "1.0-SNAPSHOT" as version
Next it will ask package



It gives package hint as com.logicx (In my case) I accept it.
Next it will ask confirmations for your choices  press "y" and enter



see you soon with next tutorial.
 next : Create maven project using intellij, dependency management, Build lifecycle etc.