Wednesday, January 26, 2011

Maven: Easy Build Tool Part I

Here I am going to post series of small posts about maven.

Introduction
Maven is a project of Apache foundation which ease the software building process.Now this is the famous project management software widely adapted across the software world.The understanding of the philosophy of the maven and familiarity with this software is essential requirement for programmers.If i tell what is maven in one sentence,maven consists of project object model (pom) ,set of standard template ,project life cycle ,a dependency management system and a logic for executing plugin goals during desired phase of the life cycle .The above feature are constructed as a module on the top of core software this is why each lifestyle event can be customized by plugins.
Project Object Model(pom.xml)
This is a XML file representing project setting.When we run the maven in a particular directory the maven scans the directory for this file and do the set up according this file.So it is mandatory for every maven project.Here the overview of the pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <!-- The Basics -->
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>
  <dependencies>...</dependencies>
  <parent>...</parent>
  <dependencyManagement>...</dependencyManagement>
  <modules>...</modules>
  <properties>...</properties>

  <!-- Build Settings -->
  <build>...</build>
  <reporting>...</reporting>

  <!-- More Project Information -->
  <name>...</name>
  <description>...</description>
  <url>...</url>
  <inceptionYear>...</inceptionYear>
  <licenses>...</licenses>
  <organization>...</organization>
  <developers>...</developers>
  <contributors>...</contributors>

  <!-- Environment Settings -->
  <issueManagement>...</issueManagement>
  <ciManagement>...</ciManagement>
  <mailingLists>...</mailingLists>
  <scm>...</scm>
  <prerequisites>...</prerequisites>
  <repositories>...</repositories>
  <pluginRepositories>...</pluginRepositories>
  <distributionManagement>...</distributionManagement>
  <profiles>...</profiles>
</project>
Maven Coordinates
Maven Coordinates is an identifier of the maven project which uniquely represents a maven project.This is used to locate the project artifact when the maven search for the project dependency in local repository.
<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.aja.javaexamples</groupId>
   <artifactId>springIOCExample</artifactId>
   <packaging>war</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>Spring IOC Example</name>
 </project> 

project descried by above minimal POM is located as $M2_REPO/com/ajajavaexamples/springIOCExampl
Usually the groubId represent the company for which the project belongs to and the artifactId uniquely represent the project with in the company .Version is a series number dictate the progress of the project.The package indicates the for example weather it is jar or war project.
Rest of the things will be covered in next post.
References:

  1. http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html?page=1
  2. http://maven.apache.org/pom.html