Social Media


Maven is a software project management tool. Its features include –

  • Build Tool
  • Dependency Management Tool
  • Deployment Tool
  • Documentation

It is also extensible thru its plugin architecture.

Archetypes are a good starting point for understanding maven. They are a templating system to allow you to quickly start your projects.

If you run –

mvn archetype:generate -DgroupId=com.glenware
This will create the directory structure below –


This gives a developer a good starting point, or if they prefer you can prepare the project to import into your favourite IDE

mvn eclipse:eclipse -Dwtpversion=2.0

The core of maven is the pom.xml –

[sourcecode language=”xml”] <project xmlns="<a href=""></a>" xmlns:xsi="<a href=""></a>"
  xsi:schemaLocation="<a href=""></a> <a href=""></a>">
  <name>SampleWebApp Maven Webapp</name>

The pom is highly configurable, as is shown here –

[sourcecode language=”xml”] <project xmlns="<a href=""></a>"
  xmlns:xsi="<a href=""></a>"
  xsi:schemaLocation="<a href=""></a>
                      <a href=""></a>">

  <!– The Basics –>

  <!– Build Settings –>

  <!– More Project Information –>

  <!– Environment Settings –>

Big projects may have multiple poms, which can be linked – for example –

[sourcecode language=”xml”]     <parent>

This produces an ‘effective-pom’ which can be seen –

mvn help:effective-pom

dependencies in maven allow you to link your project to the correct versions of jar files required in your build.

For example if you need the servlet and jsp-api’s in your project you would add these dependencies –

[sourcecode language=”xml”]         <dependency>

To import the associated jars you run –

mvn install
Maven then has a search path –

  • Search log4j in Maven local repository
  • Search log4j in Maven central repository
  • Search log4j in Maven remote repository (if defined in pom.xml)

You can add extra repositories through –

[sourcecode language=”xml”]     

You can also go offline with maven –

mvn dependency:go-offline

The bigger the pom means that you can have dependency conflicts.

These can be resolved thru –

mvn dependency:tree

mvn dependency:resolve

mvn dependency:resolve-plugins

mvn dependency:analyze – unused/undeclared dependencies

[sourcecode language=”xml”] <build>

Useful plugins –

 Execution Groups
Lifecycle – well recognised flow steps – mvn deploy
Phase – phase within a lifecycle
Plugin – Logical Grouping and distribution
Goal – Lowest unit – eg – mvn compile:compile jar:jar

 Built-in Maven Lifecycles
 mvn clean –
 clean – Remove all generated/compiled attributes prior to build
default – 
 validate – Cross check all elements necessary for build are correct and present
 compile – Primary or mixed language resources
 test – Execute unit tests
 package – Bundle module as JAR, WAR or EAR
 verify – Inspect distribution packages
 install – Install to local repository
 deploy – Upload to remote repository
site – 
 pre-site – Similar to validate
 site – Generate site
 site-deploy – deploy to remote site
mvn install -Dmaven.test.skip=true – skip tests
Eclipse –

mvn eclipse:eclipse

  Default Goal

[sourcecode language=”xml”]  <project>

Profiles allow you to create environment specific configurations – eg a test server vs a live server

mvn <yourgoal> -P YourProfile

mvn -Prelease-profile clean assembly:assembly
mvn -Pdemo clean assembly:assembly


About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: