Ramblings of a code junkie

November 19, 2006

Creating webapps with Maven

Written by

I started working on a small webapp this weekend, something that might some day become public, but who knows ;). Anyways here are some notes and examples of using maven to create a webapp, (un)deploying it to a running tomcat instance and using JSTL 1.1 in it.

First, lets create the standard layout to work with in maven, we can use the webapp archetype for this:

mvn archetype:create -DgroupId=org.credmp 

This will create the necessary structure and a simple startup webapplication. Now I want to be able to deploy it to an running tomcat instance without too much hassle; cargo to the rescue!


Cool, we can now run ‘mvn cargo:deploy’ and the built artifact will be deployed to a running instance. Right, now what? Well, I want to use JSTL 1.1 and some other things that are usefull in webapplications. First thing is to bring the web.xml up to date to version 2.4.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns=""

And lets also add the necessary jars to the pom so that they are built / used automatically.



We need the standard taglibs to be able to use JSTL taglib in the jsps.

<%@ taglib prefix='c' uri='' %>

Cool, we now have the basis to build a proper webapplication with a proper build system. For more configuration options for the cargo-maven2-plugin see the documentation.

Zarro Taags!

One comment for this post.

  1. Comment from Steve Lewis on January 6th, 2007 :

    Accurate, and succinct. I love it.

    One thing that you neglected to point out, but might be valuable to mention is that with the webbapp archetype, you have to create a few more directories yourself if you are doing anything more than a “hello world” jsp.

    The template creates a structure like this:


    you will want to create the directories for the path:


    and within there create your package directories, which should probably correspond with your groupId (the one you used during the mvn archetype:create operation)

Leave a Comment