How do I create a simple project using Maven?
Author: Deron Eriksson
Description: This tutorial describes how to create a simple project using maven.
Tutorial created using: Windows Vista || JDK 1.6.0_04


Page: < 1 2

(Continued from page 1)

Of great importance is the pom.xml file that was created in the mytest directory (the root level of the project).

pom.xml

The pom.xml (Project Object Model) file is essentially the project's metadata file that describes the various aspects of the project. It describes the project's name, group, version, dependencies, and many many other things. The contents of the generated pom.xml file are shown below.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>mytest</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>mytest</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>

Notice that the pom.xml file features an XSD. This is extremely useful since it allows us to do things such as code-completion in a good XMLW editor, such as the one in EclipseSW.

The pom.xml file has some features worth pointing out. The "modelVersion" refers to which object model the POMW is using. You rarely need to be concerned with this value. The "packaging" refers in general to the type of package that we are building with this project (such as jarW, warW, or ear). The "version" element refers to the version number of that artifact that we are building into a package. This is the number extension that comes in a package file name, such as commons-blah-1.2.3.jar. The "name" element is the display name of the project, as opposed to the "artifactId", which is the artifact file name. So, a project "name" might be "The Blah Project" while "artifactId" might be "commons-blah". The "url" element is to specify the location of the project's "site". A "site" is the generated documentation for a project.

Also, note the junit dependency that's been included in the pom.xml file. The AppTest class is a JUnit test so the project requires the junit dependency.

That about covers it for creating a basic mavenSW project using the "archetype:create" goal.

Page: < 1 2