What is a Maven?
A. Maven developed after simplified process of Jakarta Turbine project, that time various project have their own ant build files that slightly vary and jar were checked into CVS.

For making it standard for all project Maven produce by Jakarta, Maven a Yiddish word meaning accumulator of knowledge.
Maven is tool that used building for java project and their day to day building and managing activities help to java developers.

What are key features of Maven?
A. Key features of Maven as

  • Simple project setup with best practices – New project start with few steps.
  • Consistent usage across all project.
  • Superior dependency management including automatic updating, dependency.
  • Simultaneously work several project at the same time.
  • All open source repository of libraries and metadata to use, and arrangements in place with the largest Open Source projects for real-time availability of their latest releases.
  • Extensible, capable to easily write plugins in Java or scripting languages.
  • Instant access to new features with little or no extra configuration.
  • Ant tasks for dependency management and deployment outside of Maven.
  • Model based builds: Maven is able to build any number of projects into predefined output types such as a JAR, WAR.
  • Coherent site of project information: Using the same metadata as for the build process, Maven is able to generate a web site or PDF, by using bottom of the left-hand navigation of this site under the “Project Information” and “Project Reports” submenus.
  • Release management and distribution publication: Capable to integrate source control system such as CVS.
  • Dependency management: Maven encourages the use of a central repository of JARs and other dependencies. By using Perl’s CPAN on center repository for retaining jars, allows users of Maven to reuse JARs across projects and encourages communication between projects to ensure that backward compatibility issues.

Q.How to Install Maven?
A. Following steps for installation maven on windows

  • Install JDK 1.6 or above for Maven 3.x.x
  • Download latest release of Maven from maven.apache.org  & unzip it.
  • Point unzipped directory to M2_HOME on environment variable by using System Properties Advance System Setting on advance tab press Environment Variable.
  • Append path %M2_HOME%\bin;
  • Open command prompt CMD and write following command
    run mvn –version if everything fine then you will receive following output

[code lang=”plain”]
mvn –version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T02:28:10+05:30)
Maven home: D:\apache-maven-3.2.3
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_71\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
[/code]

Q.What is core concept of Maven?
A. Maven have own Meta description files POM- (Project Object Model), all activities of maven govern from pom.xml file, present on root directory. POM contains all resources related to dependencies, plugging and lifecycle management of the project by providing reference of their relative jar files.

[code lang=”xml”]
<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.javavapor.hibernate</groupId>
<artifactId>HibernateExampleXML</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>HibernateExampleXML</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
[/code]

As above snippet of pom.xml the key element of POM contains

  • project This is the top-level element in all Maven pom.xml files.
  • modelVersion This element indicates version of the object model.
  • groupId The groupId is the key identifiers of a project and based on the fully qualified domain name of organization.
  • artifactId The primary & unique artifact for a project is typically a JAR file. Secondary artifacts like source bundles and part of their final name. Maven produced pattern form -. like gameapp-1.0.jar.
  • packaging This element is responsible for the packaging type to be used by like JAR,WAR,EAR and also customizing on build process before packaging, default type is JAR.
  • version This element indicates the version of the artifact generated by the project
  • name This element indicates the display name used for the project.
  • url This element indicates where the project’s site can be found, often used in Maven’s generated documentation.
  • description This element provides a basic description of project, often used in Maven’s generated documentation

Directory structure of Maven project

[code lang=”plain”]
my-app
|– pom.xml
`– src
|– main
| `– java
| `– com
| `– mycompany
| `– app
| `– App.java
`– test
`– java
`– com
`– mycompany
`– app
`– AppTest.java

[/code]

Maven command line

[code lang=”plain”]
#Compile built with install result
mvn install

#compile exiting project
mvn compile

#comile and test existing project
mvn test

#comile but not execute test result
mvn test-compile

#making jar file
mvn package

#cleaning project
mvn clean

#if using eclips IDE
mvn eclipse:eclipse
[/code]

Below command for creating hibernate example project

[code lang=”plain”]
#for creating maven project, please remove "\" and use command in single line.
mvn archetype:generate \
-DgroupId=com.javavapor.hibernate \
-DartifactId=HibernateExampleXML \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false
[/code]

For know more old and latest archetypes of maven, visit  maven-repository.com/archetypes