HomePage | RecentChanges | Preferences

Getting Started with Maven


See http://maven.apache.org/ for information. (I'm assuming you've done this already...)

Trial Run

I ran the following in IRMApps/Projects/test:

#1 $ mvn archetype:create -DgroupId=edu.asu.vpia -DartifactId=core

#2 $ mvn archetype:create -DgroupId=edu.asu.vpia -DartifactId=site -DarchetypeArtifactId=maven-archetype-site

#3 $ mvn archetype:create -DgroupId=edu.asu.vpia -DartifactId=webapp -DarchetypeArtifactId=maven-archetype-webapp

See: [Maven Archetype Plugin Docs]

This created three directories, think of them as 'modules':

 * core, for the source code for the webapp
 * webapp, for the webapp itself
 * site, for documentation

Then I edited webapp/pom.xml to add a dependency on Struts, and on the 'core' jar (from #1 above):



(How did I know the version should be 1.0-SNAPSHOT? Because that's the default, but you could also look in core/pom.xml.)

Now add a pom.xml file at the top level (in the 'test' directory) to tell Maven that you have multiple modules in this project:

    <name>ASU IRM Test Project</name>

And from IRMApps/Projects/test, type

#4 $ mvn install

and see what happens. :) Look in the core/target and webapp/target for the results.

To clean up:

#5 $ mvn clean
which will delete all the 'target' directories.

The Parent POM

At this point, the parent knows about its children and can build the multi-module project. The next step is to tell each child about its parent, so that the things (like dependencies) that are common to all of the children can be declared in one place, in the parent pom.xml file.

To each child, add a section like this just below <project>


(The artifactId and version should match whatever is actually _in_ the top level pom.xml file.)

A Single Module Project Instead

If you'd rather work with a single module:

Now you can build the entire webapp and/or its documentation website from a single project.

Adding Displaytag

So, we know we want to use Matt Raible's awesome Displaytag library in this project. How do we go about figuring out what to add to pom.xml?

First, visit the m2 repository on ibiblio: http://www.ibiblio.org/maven2

Then look around for the obvious, is there a 'displaytag' directory? Sure enough, and if you navigate down the structure you'll end up at:


From there, you can construct the dependency:


Note that the groupId may change in the future, to (probably) 'org.displaytag', which is the package name of the library.

Installing Third Party Jars

Displaytag was easy, because it's in the central Maven repository. What about jar files that either can't be distributed (like the Servlet jars from Sun) or jars from internal projects that aren't using Maven? We do that with the 'install' plugin, for example:

$ mvn install:install-file -Dfile=webauth-2_9.jar -DgroupId=edu.asu.wmac -DartifactId=webauth -Dversion=2_9 -Dpackaging=jar

and now you can declare it as a dependency


Maven Tomcat Plugin

This one deserves its own page... MavenTomcatPlugin

The Struts Blank Archetype 1.3.0-SNAPSHOT

... is available [here]. (Not yet in a repository.)

$ mvn install:install-file
See: [Maven Install Plugin docs]

$ mvn archetype:create 

HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited November 19, 2005 2:00 pm by WendySmoak (diff)