Developing with Eclipse and Maven
Chapter 3. Creating and Importing Projects
When using Maven, project creation takes place through the use of a Maven archetype. In Eclipse, project creation takes place via the new project wizard. The new project wizard inside of Eclipse offers a plethora of templates for creating new projects. The m2eclipse plugin improves upon this wizard to provide the following additional capabilities:
-
Checking out a Maven project from a SCM repository
-
Creating a Maven project using a Maven archetype
-
Creating a Maven POM file
As shown in Figure 3.1, “Creating a New Project with m2eclipse Wizards”, all three of these options are important to developers using Maven. Let’s take a look at each one.
m2eclipse provides the ability to check out a project directly from a SCM repository. Simply enter the SCM information for a project and it will check it out for you to a location of your choice as shown in Figure 3.2, “Checkout a New Project from Subversion”:
There are additional options in this dialog for specifying a particular revision by browsing the revisions in a Subversion repository or by simply entering the revision number manually. These features reuse of some of the features in the Subclipse plugin to interact with the Subversion repository. The m2eclipse plugin supports the following SCM providers:
-
Bazaar
-
Clearcase
-
CVS
-
git
-
hg
-
Perforce
-
Starteam
-
Subversion
-
Synergy
-
Visual SourceSafe
m2eclipse offers the ability to create a Maven project using a Maven Archetype. There are many Maven Archetypes provided in the list that comes with m2eclipse as shown in Figure 3.3, “Creating a New Project with a Maven Archetype”.
The list of archetypes in Figure 3.3, “Creating a New Project with a Maven Archetype” is a list generated by something called the Nexus Indexer. Nexus is a repository manager which is introduced in "Repository Management with Nexus", a free book available from Sonatype which can be read online here: http://www.sonatype.com/books/nexus-book/reference/. The Nexus indexer is a file which contains an index of the entire Maven repository, and m2eclipse uses it to list all of the available archetypes in the entire Maven repository. When this chapter was last updated, m2eclipse had approximately ninety archetypes in this Archetype dialog. Highlights of this list include:
-
Standard Maven Archetypes to create
-
Maven Plugins
-
Simple Web Applications
-
Simple Projects
-
New Maven Archetypes
-
-
Databinder Archetypes (data-driven Wicket Applications) under
net.databinder
-
Apache Cocoon Archetypes under
org.apache.cocoon
-
Apache Directory Server Archetypes under
org.apache.directory.server
-
Apache Geronimo Archetypes under
org.apache.geronimo.buildsupport
-
Apache MyFaces Archetypes under
org.apache.myfaces.buildtools
-
Apache Tapestry Archetypes under
org.apache.tapestry
-
Apache Wicket Archetypes under
org.apache.wicket
-
AppFuse Archetypes under
org.appfuse.archetypes
-
Codehaus Cargo Archetypes under
org.codehaus.cargo
-
Codehaus Castor Archetypes under
org.codehaus.castor
-
Groovy-based Maven Plugin Archetypes (deprecated)[1] under
org.codehaus.mojo.groovy
-
Jini Archetypes
-
Mule Archetypes under
org.mule.tools
-
Objectweb Fractal Archetypes under
org.objectweb.fractal
-
Objectweb Petals Archetypes under
org.objectweb.petals
-
ops4j Archetypes under
org.ops4j
-
Parancoe under
org.parancoe
-
slf4j Archetypes under
org.slf4j
-
Springframework OSGI and Web Services Archetypes under
org.springframework
-
Trails Framework Archetypes under
org.trailsframework
[1]And these were just the archetypes that were listed under the Nexus Indexer Catalog, if you switch Catalogs you'll see other archetypes. While your results may vary, the following additional archetypes were available in the Internal Catalog:
-
Atlassian Confluence Plugin Archetype under
com.atlassian.maven.archetypes
-
Apache Struts Archetypes under
org.apache.struts
-
Apache Shale Archetypes under
org.apache.shale
A catalog is simply a reference to a repository index. You can manage the set of catalogs that the m2eclipse plugin knows about by clicking on the
button next to the catalog drop down. If you have your own archetypes to add to this list, you can click on .Once you choose an archetype, Maven will retrieve the appropriate artifact from the Maven repository and create a new Eclipse project with the selected archetype.
m2eclipse provides the ability to create a Maven module. Creating a Maven module is almost identical to creating a Maven project as it also creates a new Maven project using a Maven archetype. However, a Maven module is a subproject of another Maven project typically known as a parent project.
When creating a new Maven module you must select a parent project that already exists inside of Eclipse. Clicking the browse button displays a list of projects that already exist as shown in Figure 3.5, “Selecting a Parent Project for a New Maven Module”:
After selecting a parent project from the list, you are returned to the New Maven Module window and the Parent Project field is populated as shown in Figure 3.4, “Creating a New Maven Module”. Clicking will then display the standard list of archetypes from Section 3.1.2, “Creating a Maven Project from a Maven Archetype” so you can choose which one should be used to create the Maven module.
[1] Don't use the Groovy Maven Plugin in Codehaus' Mojo project. Jason Dillon has moved the Groovy Maven integration to the Groovy project in codehaus. For more information see http://groovy.codehaus.org/GMaven.