Maven is a Project Management tool. It allows you to keep track of the releases and documentation of your project and use other projects in your project(dependencies). It wraps all this information up in an XML file called the Project Object Model (POM)
So, why use Maven when we already have excellant version control systems like GIT.
The main benifit of Maven is transitive dependencies. Suppose I have Project A that requires Project B to work. We can add B directly to the POM and Maven will build it for us. Now, Suppose B requires Project C. We don't have to do anything. When compiling B, Maven automatically will add C to our Build Path
If you want to look at why people use Maven take a look here
Download Maven from this link and extract it from its zip folder.
Computer > Properties > Advanced System Settings > Environment Variables
JAVA_HOME
value: {JAVA_PATH}
, for example C:\Program Files\Java\jdk1.6
MAVEN_HOME
value: {MAVEN_PATH}
, for example C:\Program Files\maven
;
) {MAVEN_PATH}\bin
Now test by going to Command Prompt and typing mvn
. If the command prompt does not say 'mvn' is not recognized
then its installed correctly
To create a Maven Project we use the following command
mvn archetype:generate -DgroupId={YOUR_PACKAGE} -DartifactId={YOUR_NAME} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
DarchetypeArtifactId
: Defines the basic archetype the project will use. You can read more about it hereDinteractiveMode
: If set to true it will ask you for all the options not specified while running the command. If set to false it will assume themTo allow your new Maven Project to be used in Eclipse you have to
Go to the project folder in the command line and run this command : mvn eclipse:eclipse
M2_REPO
in EclipseThis is called a classpath variable. Whenever you have a maven project in eclipse you need dependencies from you Maven Repo. This will set that variable. To do this type this command in the Command Line
mvn -Declipse.workspace="your Eclipse Workspace" eclipse:configure-workspace
In Eclipse File > Import > General > Existing Projects into Workspace > Select project folder > Finish.
Now you have a fully functioning Maven project in Eclipse. You can edit the pom.xml
to pull dependencies and update your version.