q Maven is a popular open source build tool used primarily
for Java projects. It was designed to make build
process easier task.
q Apart from being a build tool Maven can also manage
reporting and documentation from a central piece of
q It is based on the concept of a project object model
q Maven is more than just a "build tool" rather is a
project management tool.
Maven provides developers ways to manage following:
q Mailing list
Here are some of the benefits of using Maven over any
other build (Ant, make etc) :
q Standardized project layout. (Convention over
configuration unlike ANT)
q Automatic dependency handling.(Ant can't do this
q Large Existing repository.
q Reusability ( through Maven Plugins).
q Maven is a Java tool, so you must have Java installed in
order to proceed.
q Follow the instructions on the link for intallation :
q Once installation is done type the following command in
a terminal or in a command prompt:
It should print out your installed version of Maven
q Build Lifecycle is a well defined sequence of phases
which define the order in which the goals are to be
executed. Here phase represents a stage in life cycle.
q When Maven starts building a project, it steps through
a defined sequence of phases and executes goals which
are registered with each phase. Maven has following
three standard lifecycles:
q default(or build)
q A Build Lifecycle is Made Up of Phases.
q A Build Phase is Made Up of Plugin Goals.
q A Plugin Goal represents a specific task (finer than a
build phase) which contributes to the building and
managing of a project.
lProject Object Model
q POM stands for Project Object Model. It is
fundamental Unit of work in Maven.
q It is an XML file. It always resides in the base
directory of the project as pom.xml.
q The POM contains information about the project and
various configuration detail used by Maven to build the
lSome of the configuration that can be specified in the
POM are following:
q project dependencies
q build profiles
q project version
q mailing list
q A maven repository is a directory of packaged JAR file with
pom.xml file. Maven searches for dependencies in the
repositories. There are 3 types of maven repostory :
§ Local Repository
§ Central Repository
§ Remote Repository
q Maven searches for the dependencies in the following order:
q Local repository then Central repository then Remote
q Local Repository :-
§ Maven local repository is located in your local
system. It is created by the maven when you run
any maven command.
§ By default, maven local repository is
%USER_HOME%/.m2 directory. For example:
q Central Repository :-
§ Maven central repository is located on the web. It
has been created by the apache maven community
§ The path of central repository is:
q Remote Repository :-
§ Maven remote repository is located on the web.
Most of libraries can be missing from the central
repository such as JBoss library etc, so we need to
define remote repository in pom.xml file.
q A Build profile is a set of configuration values which can be
used to set or override default values of Maven build. Using
a build profile, you can customize build for different
environments such as Production v/s Development
q Build profiles are majorly of three types :
§ Per Project :- Defined in the project POM file, pom.xml
§ Per User :- Defined in Maven settings xml file
§ Global :- Defined in Maven global settings xml file
q Plugins are the central feature of Maven that allow for the
reuse of common build logic across multiple projects.
q Maven is actually a plugin execution framework where every
task is actually done by plugins.
q A plugin generally provides a set of goals and which can be
executed using following syntax:
ü mvn [plugin-name]:[goal-name]
q There are plugins for almost every task in maven like plugins
are used to: create jar files, create war files, compile code,
unit test code, create project documentation, and on and on.
q Maven provides following two types of Plugins:
1)Build plugins:- They execute during the build and should be
configured in the <build/> element of pom.xml .
2)Reporting plugins:-They execute during the site
generation and they should be configured in the
<reporting/> element of the pom.xml .
lAn archetype is defined as an original pattern or model from
which all other things of the same kind are made.
lMaven provides users,a very large list of different types of
project templates using concept of Archetype. Maven helps
users to quickly start a new java project using following
lArchetype is a Maven plugin whose task is to create a project
structure as per its template. Archetype Plugin allows the user
to create a Maven project from an existing template called an
q For creating any project maven provides templates(Archetype),
using which one can create by selecting any one archetype from
q To start a new Maven project, use the Maven Archetype plugin from
the command line. Run the following command :-
§ mvn archetype:generate -DarchetypeGroupId=[Group Id] -
DarchetypeArtifactId= [Artifact ID]
q You can search for all archetypes provided by maven at there
central repository (http://search.maven.org/) and all other 3rd
party archetypes at any remote repository like -
q SNAPSHOT is a special version that indicates a current
q Unlike regular versions, Maven checks for a new
SNAPSHOT version in a remote repository for every build.
q Snapshot vs Version :-
q In case of Version, if Maven once downloaded the mentioned
version say data-service:1.0, it will never try to download a
newer 1.0 available in repository. To download the updated
code, artifact version is be upgraded to 1.1.
q In case of SNAPSHOT, Maven will automatically fetch the
latest SNAPSHOT (data-service:1.0-SNAPSHOT)
everytime app-ui team build their project.
Hey did you notice ???
What we did till now automated the build
process. And this is called Build
Automation using Maven
q Team communication is an essential part of any
project. And wasting time looking for technical project
information can be costly and frustrating. Clearly, any
IT project will benefit from having its own dedicated
q That's where the Maven site generator steps in. With
little effort, you can have a professional-quality, low
maintenance project Website up and running in no time.
q Documentation is generated by running
§ mvn site