Maven 3 Tutorial – Project Setup

June 11th, 2011 by David Kessler Leave a reply »

Multiple Artifacts from a Single Source

Maven restricts projects to one artifact per ‘pom’ file. While we can argue whether this is the right approach, there is a simple solution. If you have a project called ‘sample-service’ that produces a WAR and you want to create a JAR from the same source code then you need to create a second package containing a single pom file.


The ‘sample-client’ pom is configured to point to ‘sample-service’ for it’s source files. This should be added to the ‘build-helper-maven-plugin’ configuration. Please refer to for more information.


Release Plugin

This is a very powerful plugin. If you’ve ever released a project by hand you will appreciate this plugin. One of my favorite features is that it checks to see if all of the dependencies refer to released versions. Without this automatic check you are forced to search through all of the dependency management configurations for unreleased dependencies. Depending on the size of your hierarchy this can be quite painful.

Along with this dependency check it also runs all of the tests, tags the code with the release name, and publishes the artifacts in the Maven repository. This plugin embodies the best standards for releasing within our industry. Standards that I easily forget and/or mess up. I highly recommend that you use this plugin to release your projects. Please refer to for more information.

Aggregate POM

An aggregate POM joins multiple modules together.

_pom.xml (aggregate)
    |_pom.xml (module 1)
    |_pom.xml (module 2)

The aggregate pom configures multiple modules in the modules section.


When you execute a Maven command at the aggregate level it will execute the same command on all of the configured modules. If any of these modules depends on another module Maven builds them in the correct order. This is a simple way to break up a large project into focused modules without loosing a coordinated project management strategy. While this could be replicated with Ant and Ivy it would be painful to configure and maintain. Aggregate projects are first class citizens in Maven.

Dependency Management

The ‘dependencymanagement’ section defines the acceptable versions for a project. This configuration does not result in a JAR being downloaded and included in the project. On the other hand, this is a directive specifying which version of a dependency should be used if a project depends on it. This is a simple way to force Maven to select a specific dependency version. In the case of an aggregate project it is best to add this to the aggregate pom. Configure the dependency versions in one place for all of the modules.


Distribution Zip

Maven provides a simple way to package all of your artifacts in a single zip file. This simplifies the deployment process and increases traceability. For example I have used this feature to package my WAR, SQL, and external PDF files in the same zip file. Our deployment team extracted the WAR and PDF files and deployed them. Then they passed the SQL on to the DBA’s to run the scripts. All of the files necessary to deploy our project were packaged together and published to our Maven repository. Please refer to for more information.


Maven provides a holistic approach to project management. Maven provides standard conventions that can be easily modified and extended. When our development team switched from Ant/Ivy to Maven we spent less time focusing on how to build our projects. In the end Maven provided industry project management standards that we could depend on. Even when we spent hours trying to perfect our Ant build process we were getting some things wrong. We were focused on deploying the product at that moment. Unfortunately companies need to insure that deployments are traceable, dependable, and reproducible. Maven freed us up to focus on getting the product out while protecting our companies interests right out of the box.



  1. Akrem Saed says:

    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. mark says:

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

  3. mark says:

    I guess that’s a wordpress issue (- – instead of -)

  4. mark says:

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

  5. David Kessler says:

    I fixed ‘eclipze.exe’. Nice catch. Thank you.

  6. David Kessler says:

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

  7. greg says:

    correcting the corrector

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

  8. Akrem Saed says:

    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


  9. john says:

    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?

  10. David Kessler says:

    Good catch. I updated it with smaller .jpg files. Thank you.

  11. Andi says:

    after many days – with this tutorial maven run , thanks

  12. Apache Omega says:

    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?

  13. Travis Klotz says:


    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.


  14. Adel M says:

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

  15. David Kessler says:

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

  16. Alvi says:


    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]

  17. David Kessler says:

    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.

  18. Alvi says:

    Thanks David kessler now its work

  19. This post is great I’m glad I found it

  20. Tory Barren says:

    This is simply supurb, very indepth, thank you.

  21. Mara says:

    very good submit, i definitely love this website, carry on it

  22. Abdul Mannan Khan says:

    kudos.. Great tutorial for start-up.

  23. Vikas says:

    Great!!!! Above steps worked for me. Thanks.

  24. Jay Ungerland says:

    “Build Success!”

    Many, many thanks for this detailed and lucid tutorial.

  25. oussama smiai says:

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

  26. vishu says:

    its very good…..


  27. shamna says:

    Could you please help me how to create a login and registration page using maven??

  28. David Kessler says:

    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.

  29. 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

  30. saad says:

    thank so much

  31. baba khan says:

    very good tutorial.. and so helpfull

Leave a Reply