Creating your first Maven Project
To create your first project, you will use Maven’s Archetype mechanism. An archetype is defined as an original pattern or model from which all other things of the same kind are made. In Maven, an archetype is a template of a project, which is combined with some user input to produce a fully-functional Maven project. This chapter will show you how the archetype mechanism works, but if you would like more information about archetypes, please refer to the Introduction to Archetypes.
To create the Quick Start Maven project, execute the following:
C:mvnbook> mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app
You will notice a few things happened when you executed this command. First, you will notice that a directory named
my-app has been created for the new project, and this directory contains your
pom.xml, which looks like the following:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Maven Quick Start Archetype</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
At the top level of every project is your pom.xml file. Whenever you see a directory structure, which contains a
pom.xml file, you know you are dealing with a Maven project. After the archetype generation has completed, you will notice that the following directory structure has been created, and that it in fact adheres to Maven’s standard directory layout discussed in Chapter 1.
Figure 1-1: Directory structure after archetype generation
src directory contains all of the inputs required for building, testing, documenting, and deploying the project (source files, configuration files, various descriptors such as assembly descriptors, the site, and so on). In this first stage you have Java source files only, but later in the chapter you will see how the standard directory layout is employed for other project content.
Now that you have a POM, some application sources, and some test sources, you are ready to build your project.