To start a new Maven project, use the Maven Archetype plugin from the command line.
$ mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 \
-DartifactId=simple \
-DpackageName=org.sonatype.mavenbook
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for
updates from central
[INFO] -----------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] --------------------------------------------------------------------
[INFO] [archetype:create]
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: \
checking for updates from central
[INFO] Parameter: groupId, Value: org.sonatype.mavenbook.ch03
[INFO] Parameter: packageName, Value: org.sonatype.mavenbook
[INFO] Parameter: basedir, Value: /Users/tobrien/svnw/sonatype/examples
[INFO] Parameter: package, Value: org.sonatype.mavenbook
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: simple
[INFO] * End of debug info from resources from generated POM *
[INFO] Archetype created in dir: /Users/tobrien/svnw/sonatype/examples/simple
mvn is the Maven 2 command.
archetype:create is called a Maven goal. If you
are familiar with Apache Ant, a Maven goal is analogous to an
Ant target; both describe a unit of work to be completed in a build. The
-Dname=value pairs are arguments that are passed to the
goal and take the form of -D properties, similar to the
system property options you might pass to the Java Virtual Machine via the
command line. The purpose of the archetype:create goal
is to quickly create a project from an archetype. In this context,
an archetype is defined as “an original model or type after
which other similar things are patterned; a prototype.”[2] A number of archetypes are available in Maven for anything
from a simple Swing application to a complex web application. In this
chapter, we are going to use the most basic archetype to create a simple
skeleton starter project. The plugin is the prefix
archetype, and the goal is
create.
Once we've generated a project, take a look at the directory structure Maven created under the simple directory:
simple/simple/pom.xml
/src/ /src/main/
/main/java /src/test/
/test/java
This generated directory adheres to the Maven Standard Directory Layout. We’ll get into more details later in this chapter, but for now, let’s just try to understand these few basic directories:
The Maven Archetype plugin generated a single class
org.sonatype.mavenbook.App, which is a 13-line Java
class with a static main function that prints out a message:
package org.sonatype.mavenbook;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
The simplest Maven archetype generates the simplest possible program: a program which prints "Hello World!" to standard output.





