Maven 3 Tutorial – Project Setup

  • Overview
    • What is Maven?
    • Plugins
    • Why not Ant and Ivy?
    • But It Downloads the Internet
  • Getting Started
    • Install
    • What is a POM?
    • Convention over Configuration
    • New Project
  • Project Management
    • Parent POM
    • Local Maven Repository
    • Multiple Artifacts from a Single Source
    • Release Plugin
    • Aggregate POM
    • Dependency Management
    • Distribution Zip
  • Conclusions


What is Maven?

Maven is a software project management and comprehension tool that includes: build tools, dependency management, project reporting and much more.  I say “much more” because at the core Maven is a plugin execution framework.  There are plugins supported by the Maven project (, plugins supported by Mojo Project (, and third party plugins.  If you can find or write a plugin, Maven can run it.


Plugins are configured to run during specific phases in the Maven lifecycle.  The high-level phases that make up the build lifecycle include: validation, compile, test, package, integration-test, verify, install, and deploy.  An exhaustive list of build phases can be found at

Why not Ant and Ivy?

People always gravitate to this question of whether Maven is better than Ant and Ivy.  Unfortunately this is not a fare comparison.  Ant is a build tool and Ivy is a dependency management tool.  Maven is not just a build tool or just a dependency management tool.  On the contrary, Maven is a project management tool that embodies software development best practices.

To illustrate this point I will share a story from my early years in software development.  Our shop used Ant without Ivy.  Ivy didn’t become a full fledged Apache project until October, 2007.  Each team had their own Ant build.  As we began to move from team to team we had to find out which targets needed to be run.  Over time we decided on a set of names that every team needed to implement.  This helped but just because the target was named the same thing it did not mean they worked the same way.

Long story short, we began to meet to create a shared standard.  During this long process we were introduced to Maven.  Ironically, Maven had accepted standards for many of the issues that we were trying address.  Maven was not just a standard for our company it was a standard for all Maven users.  New employees that were familiar with Maven had a good grasp of how we managed our projects.

Maven provided a standard that not only addressed our concerns as software developers.  It provided a standard solution that supported our corporate: audits, disaster recovery, tracability, and the list goes on.  We were trying to reinvent the wheel with Ant when the Maven community had already solved these problems.

Ant and Ivy are powerful ingredients for designing a custom build process.  Maven however is a powerful solution for building and managing software.  In our case we wanted a solution instead of the ingredients and tools to create our own solution.  Maven satisfied our needs and saved us significant time and money.

But It Downloads the Internet

I can’t tell you how many people have told me that they don’t like Maven because it “downloads the internet”. I find it ironic that many of them like Ivy.  I hate to break the news, but Ivy downloads the internet too. I’m not sure why this is a concern.  Is there a fear that Maven will fill up their hard drive?  Disk space is cheap.  The computer I am working on right now has 150GB of hard disk space and my Maven local repository is eating up 300MB of it.  This computer has pleanty of room for more of the internet.

I recall the first time that I tried to setup a new project without a dependency management tool.  I spent over a week trying to download the correct version of each JAR.  I was ready to take a vacation by the time I finished this ugly puzzle.  After using Maven and Ivy for managing my  dependencies I will never go back.  By the time I downloaded all the JARs that we needed, I felt like I had in fact downloaded the entire internet.

I love dependency management tools and they can have as much of my hard drive as they need.


  1. I always wanted to start using Maven along with Archiva for some time now, and this just helped me to jump start that … excellent post, thanks david

  2. ‘eclipze.exe’ should be ‘eclipse.exe’. and thanks thanks thanks for the extremely helpful post

  3. Both ‘mvn –version’ and ‘mvn -version’ work for me. I updated it to the latter. Thank you.

  4. correcting the corrector

    acording to mvn -help it should be “mvn –version” instead of “mvn -version”

  5. one little issue I encountered was maven was not downloading dependencies from repository locations defined in a project pom.xml

    the pom had the following :
    <name>Spring by Example</name>

    <name>SpringSource Enterprise Bundle Repository – SpringSource Bundle Releases</name>
    <name>SpringSource Enterprise Bundle Repository – External Bundle Releases</name>
    <name>Spring Milestone Maven Repo</name>

    <name> Maven 2 Repository</name>

    but since I configured Archiva to ONLY mirror central but in the maven settings.xml file we used

    the * was the problem because we are telling maven to always use archiva as the mirror , but Archiva is only mirroring two repositories . To fix this , we changed the last one to


  6. Your screenshots are .bmp files. I just can’t believe it. Page 3 of this article nearly weights 100 MB. I’m glad you made this tutorial but, seriously, .bmp?

  7. I’ve been trying for days to get maven running and it just wont work.
    I type in mvn -version and it says mvn is not recognized
    what the hell am i doing wrong?

  8. Omega,

    It sounds like you do not have M2_HOME/bin on your Path. So when you try to execute the command, it had no idea where the program is.


  9. Very nice overview of Maven! but please do something about the missing xml tags on the xml examples. Thanks!

  10. Thank you. Nice catch. I’m not sure how the xml tags got stripped off of this post but I added them back.

  11. Hei,

    I follow the tutorial very well but when i run mvn install i got following error. Can some one tell me what i miss.. thanks

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project onlineweb: Error assembling WAR: webxml attribute i
    s required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project inmo
    bilweb: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(
    at org.apache.maven.DefaultMaven.doExecute(
    at org.apache.maven.DefaultMaven.execute(
    at org.apache.maven.cli.MavenCli.execute(
    at org.apache.maven.cli.MavenCli.doMain(
    at org.apache.maven.cli.MavenCli.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(
    Caused by: org.apache.maven.plugin.MojoExecutionException: Error assembling WAR:
    webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
    at org.apache.maven.plugin.war.WarMojo.execute(
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
    … 19 more
    Caused by: org.codehaus.plexus.archiver.ArchiverException: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
    at org.codehaus.plexus.archiver.war.WarArchiver.initZipOutputStream(
    at org.codehaus.plexus.archiver.AbstractArchiver.createArchive(
    at org.apache.maven.archiver.MavenArchiver.createArchive(
    at org.apache.maven.plugin.war.WarMojo.performPackaging(
    at org.apache.maven.plugin.war.WarMojo.execute(
    … 21 more
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1]

  12. I was able to reproduce this issue with the following steps.
    1. Create new Maven Project
    2. check ‘Create a simple project (skip archetype selection)
    3. next
    4. add groupId/artifactId
    5. change the packaging to ‘war’
    6. finish
    7. Run As -> Maven install

    The reason that you’re getting this message is that there isn’t a ‘web.xml’ file in ‘src/main/java/webapp/WEB-INF’

    You can either add a ‘web.xml’ file to this directory or you can use a Maven archetype. To use an archetype follow these steps.

    1. Create new Maven Project
    2. uncheck ‘Create a simple project (skip archetype selection)
    3. next
    4. select ‘All Catalogs’
    5. Filter = ‘maven-archetype-webapp’
    6. select ‘maven-archetype-webapp’
    7. next
    8. add groupId/artifactId
    9. finish

    This will create a ‘web.xml’ file for you.

    Hope this helps.

  13. Your tutorial is very helpful, I wish I can find a tutorial about configuring settings.xml and M2_REPO variable

  14. Maven is not a web framework. You need to look into Spring MVC or Grails or some kind of web framework to create a login and registration page.

  15. when i am opening pom.xml,acoording to this ,i have select plug-in.but i am not geeting that option when i was open pom.xml.i am geeting window like Overview ……what i have to do ,to select plug-in

Comments are closed.