Maven: The Complete Reference - 12.3. Available Archetypes |
|
As more and more projects adopt Maven, more and more artifacts are being published by projects as a way to provide users with a quick way of creating projects from existing templates. This section discusses some of the simple core archetypes from the Apache Maven project as well as providing a survey of some interesting third-party archetypes. Some of the most straightforward Maven archetypes are contained in the org.apache.maven.archetypes groupId. Most of the basic archetypes under org.apache.maven.archetypes are very basic templates that include few options. You’ll use them only to provide the most basic features that distinguish a Maven project from a non-Maven project. For example, the webapp archetype plugin described in this section just includes a stub of a web.xml file in ${basedir}/src/main/webapp/WEB-INF, and it doesn’t even go as far as providing a Servlet for you to customize. In Section 12.3.2, “Notable Third-Party Archetypes” you’ll see a quick survey of some of the more notable third-party archetypes such as the AppFuse and Cocoon artifacts. The following archetypes can be found in the groupId
The quickstart archetype is a simple project with JAR packaging and a
single dependency on JUnit. After generating a project with the
quickstart archetype, you will have a single class named This archetype creates a simple project with WAR packaging and a single dependency on JUnit. ${basedir}/src/main/webapp contains a simple shell of a web application: an index.jsp page and the simplest possible web.xml file. Even though the archetype includes a dependency on JUnit, this archetype does not create any unit tests. If you were looking for a functional web application, this archetype is going to disappoint you. For more relevant web archetypes, see Section 12.3.2, “Notable Third-Party Archetypes”. This archetype creates a simple project with This section is going to give you a brief overview of some of the
archetypes available from third-parties not associated with the Apache
Maven project. If you are looking for a more comprehensive list of
available archetypes, take a look at the list of archetypes in
m2eclipse. m2eclipse allows you to create a new Maven project from an
ever growing list of approximately 80 archetypes which span an amazing
number of projects and
technologies. Creating
a Maven Project from a Maven Archetype in
"Developing with Eclipse
and Maven" contains a list of archetypes which are immediately
available to you when you use m2eclipse. The archetypes listed in this
section are available on the default list of archetypes generated by
the interactive execution of the AppFuse is an application framework developed by Matt Raible. You can
think of AppFuse as something of a Rosetta Stone for a few very
popular Java technologies like the Spring Framework, Hibernate, and
iBatis. Using AppFuse you can very quickly create an end-to-end
multi-tiered application that can plugin into several front-end web
frameworks like Java Server Faces, Struts, and Tapestry. Starting with
AppFuse 2.0, Matt Raible has been transitioning the framework to Maven
2 to take advantage of the dependency management and archetype
capabilities. AppFuse 2 provides the following archetypes all in the
groupId
Archetypes following the $ mvn archetype:generate \ -DarchetypeArtifactId=appfuse-modular-spring \ -DarchetypeGroupId=org.appfuse.archetypes \ -DgroupId=org.sonatype.mavenbook \ -DartifactId=mod-spring \ -Dversion=1.0-SNAPSHOT \ -DinteractiveMode=false[INFO] Scanning for projects... ... [INFO] [archetype:generate] [INFO] Generating project in Batch mode [INFO] Archetype [org.appfuse.archetypes:appfuse-modular-spring:RELEASE] found in catalog [INFO] Parameter: groupId, Value: org.sonatype.mavenbook [INFO] Parameter: packageName, Value: org.sonatype.mavenbook [INFO] Parameter: basedir, Value: /Users/tobrien/tmp [INFO] Parameter: package, Value: org.sonatype.mavenbook [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: artifactId, Value: mod-spring ... [INFO] OldArchetype created in dir: /Users/tobrien/tmp/mod-spring [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL $ cd mod-spring $ mvn ... (an overwhelming amount of activity ~5 minutes) $ cd web $ mvn jetty:run-war ... (Maven Jetty plugin starts a Servlet Container on port 8080) From generating a project with the AppFuse archetype to running a web application with a authentication and user-management system takes all of 5 minutes. This is the real power of using a Maven Archetype as a foundation for a new application. We oversimplified the AppFuse installation process a bit and left out the important part where you download and install a MySQL database, but that’s easy enough to figure out by reading the AppFuse Quickstart Documentation. Atlassian has created some archetypes for people interested in
developing plugins for both Confluence and JIRA. Confluence and JIRA
are, respectively, a Wiki and an issue tracker both of which have
gained a large open source user base through granting free licenses
for open source projects. Both the For more information about developing Confluence plugins with Maven 2, see Developing Confluence Plugins with Maven 2 on the Confluence project’s Wiki. For more information about developing Jira plugins with Maven 2, see How to Build and Atlassian Plugin on the Atlassian Developer Network. Apache Wicket is a component-oriented web framework which focused on managing the server-side state of a number of components written in Java and simple HTML. Where a framework like Spring MVC or Ruby on Rails focuses on merging objects within a request with a series of page templates, Wicket is very strongly focused on capturing interactions and page structure in a series of POJO Java classes. In an age where hype-driven tech media outlets are proclaiming the "Death of Java", Wicket is a contrarian approach to the design and assembly of web applications. To generate a Wicket project with the Maven Archetype plugin: $ mvn archetype:generate ... (select the "wicket-archetype-quickstart" artifact from the interactive \ menu) ... ... (supply a groupId, artifactId, version, package) ... ... (assuming the artifactId is "ex-wicket") ... $ cd ex-wicket $ mvn install ... (a lot of Maven activity) ... $ mvn jetty:run ... (Jetty will start listening on port 8080) ... Just like the AppFuse archetype, this archetype creates a shell web application which can be immediately executed with the Maven Jetty plugin. If you hit http://localhost:8080/ex-wicket, you be able to see the newly created web application in a servlet container. NoteThink about the power of Maven Archetypes versus the copy and paste approach that has characterized the last few years of web development. Six years ago, without the benefit of something like the Maven Archetype plugin, you would have had to slog through a book about AppFuse or a book about Wicket and followed circuitous pedagogy about the framework before you could actually fire it up in servlet container. It was either that or just copying an existing project and customizing it for your needs. With the Maven Archetype plugin, framework developers can now give you a working, customized shell for an application in a matter of minutes. This is a sea change that has yet to hit the enterprise development space, and you can expect that this handful of available third-party artifacts will balloon to hundreds within the next few years. |