Sunday, 27 April 2014

Create Maven Project

How to create a simple project using maven.

Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software: First, it describes how software is built, and second, it describes its dependencies. 

Maven Standard Directory should be like that






Every Maven project has what is known as a Project Object Model (POM) in a file named pom.xml. This file describes the project, configures plugins, and declares dependencies.



Source code and resources are placed under src/main. In the case of our simple Java project this will consist of a few Java classes and some properties file. In another project, this could be the document root of a web application or configuration files for an application server.



Test cases are located in src/test. Under this directory, Java classes such as JUnit or TestNG tests are placed in src/test/java



Maven dynamically downloads Java libraries and Maven plug-ins from one or more repositories such as the Maven 2 Central Repository, and stores them in a local cache


 Maven has 3 type of repository

1- Local
2- Central
3- Remote

By default maven’s local repository exist on following path :

C:/Documents and Settings/.m2/repository


Create simple Maven Project

mvn archetype:create -DgroupId=com.test -DartifactId=mytest



 if maven cant   find any dependency in local repository, starts searching in central repository using following URL: http://repo1.maven.org/maven2/


POM xml :

It describes the project's name, group, version, dependencies, and many many other things. The contents of the generated pom.xml file are shown below. 



Build lifecycle

One of Maven's standard lifecycles is the default lifecycle, which includes the following phases