Monday, August 25, 2014

What is Maven? How to configure Maven in your Project

Maven is a build Automation tool for Java Projects. It addresses two aspects of building software
1)How the Software is build
2)what are its dependencies

When you create your maven project you can see the following directories getting created
Directory namePurpose
project homeContains the pom.xml and all subdirectories.
src/main/javaContains the deliverable Java sourcecode for the project.
src/main/resourcesContains the deliverable resources for the project, such as property files.
src/test/javaContains the testing Java sourcecode (JUnit or TestNG test cases, for example) for the project.
src/test/resourcesContains resources necessary for testing.
So in this way it tells how the software is to be built

Now lets see, it resolves the problem of dependcies

To manage dependencies say JUnit, all you need to do is, simply  declare JUnit project coordinates in its POM
eg :  <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>

So everytime you run your maven build it automatically downloads the version of JUnit as said in POM.xml
Next time, when you use say, 4.0 verson of Junit all you need to do is just to update a single line in your POM.xml

In this way it helps you to manage your dependencies

Steps to configure Maven in your Project

1)Download Maven Jars
2)Configure M2_HOME and path vars
3)To check if Maven is installed go to cmd prompt and type mvn --version it shd not show any error
4) Go to folder where you need to create project and type mvn archetype:generate
it will create a project
5)go to project folder and type mvn eclipse:eclipse it will create eclipse project
6) import the project to eclipse and do your coding
7) Maven will create src/test/java and src/main/java folder in src/test/java you can write all your test code
8) it will also create your pom.xml at project level
9)Update the pom.xml with maven dependencies for selenium, unit, testNG
10) go to cmd prompt and type mvn package, download all jars, it will compile and create jar file of your project
once done you can install your project directly to test env or deploy to other env directly with mvn

Maven is a industry standard way may to maintain your code be it for development/automation

You can find more information on http://maven.apache.org/index.html

Build Lifecycle of Maven 

 validate
 generate-sources
 process-sources
 generate-resources
 process-resources
 compile
 process-test-sources
 process-test-resources
 test-compile
 test
 package
 install
 deploy

Maven Integration with Eclipse

I found a good link that shows integration http://www.tutorialspoint.com/maven/maven_eclispe_ide.htm

No comments:

Post a Comment