Translations of this page:

Maven Archetypes

An archetype provides a template for a project. We used the default archetype in our example but if we had been building a Web application we could have used the webapp archetype. You can thing of these as patterns for the project structure. They can ensure consistency between projects, developers and development teams with the benefits of shorter learning curve for new staff and improved long-term maintenance.

$ mvn archetype:create -DgroupId=com.abcseo -DartifactId=myapp
   -DarchetypeArtifactId=maven-archetype-webapp

This generates the following directory structure

myapp
 |-- pom.xml
 `-- src
    `-- main
            `-- resources
                 `-- webapp
                      |-- index.jsp
                      `-- WEB-INF
                           `-- web.xml

To create a simple J2EE application use the following archetype

$ mvn archetype:create -DgroupId=com.abcseo -DartifactId=myapp
   -DarchetypeArtifactId=maven-archetype-j2ee-simple

You will notice more than one Project Object Model - POM in the directory tree

myapp
  |-- pom.xml
  |-- ear
  |    |-- pom.xml
  |    `-- ejbs
  |         |-- pom.xml
  |         `-- src
  |              `-- main
  |                   `-- resources
  |                        `-- META-INF
  |                             `-- ejb-jar.xml
  |-- primary-source
  |    `-- pom.xml
  |-- projects
  |-- pom.xml
  |    `-- logging
  |         `-- pom.xml
  |-- servlets
  |    |-- pom.xml
  |    `-- servlet
  |         |-- pom.xml
  |         `-- src
  |              `-- main
  |                   `-- webapp
  |                        |-- index.jsp
  |                        `-- WEB-INF
  |                             `-- web.xml
  `-- src
       `-- main
            `-- resources

The Maven repository website has a full list of archetypes. There is even an archetype to build new Maven archetypes called, logically, maven-archetype-archetype; this creates an archetype similar to quickstart. This is useful to produce customized project layouts with project specific resources.

An archetype doesn't delete an existing project so you can run Maven on an existing project to create a pom.xml file and the desired directory layout.

tech/java/maven-archetypes.txt · Last modified: 2007/09/09 14:28 by davidof
Recent changes RSS feed