This is a short introduction on the basic features of Maven and how to use them.
This section gives a brief overview on how to install Maven on your system.
Maven version: 2.2.1 Java version: 1.6.0 OS name: "Windows XP"
This section shows how to create a project and configure the necessary files for your own needs.
This part shows how to create a new project with Maven Archetypes and introduces the project structure.
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.mycompany.app -DartifactId=my-app
The following project structure will be created by Maven:
my-app |- src | |- main | | `- java | | `- com | | `- mycompany | | `- app | | `- App.java | `- test | `- java | `- com | `- mycompany | `- app | `- AppTest.java `- pom.xml
This chapter covers the configuration of the POM for usage in an individual project.
The pom.xml is the main configuration file of a Maven project. In its basic form (after the creation) only few values exist within the file. The structure of the file is pictured below:
<project> <modelVersion>4.0.0</modelVersion> <groupId>at.ac.tuwien.ifs.qse</groupId> <artifactId>projekt</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>projekt</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> </dependencies> </project>
This section introduces the phases of the Maven build process and how to use them.
To clean the target folders, use the command
The Clean Plugin can also be configured to clean other directories than the target folder. For further information read the Plugin documentation.
To package the class files to format defined in the POM, use:
To install the packaged project in the Maven 2 repository, use:
To build and install the project, go into the root of the project and run the command:
Maven 2 will automatically identify and download needed ressources. This is only done during the first time; the downloaded dependencies will be stored in your local Maven repository (M2_HOME). The POM is configured to use a mirror of the repository at the QSE, but even so, you might encounter timeouts during the initial download. Simply restart the build process.
The output of the build process (class files, the project site etc.) is stored in the target/subdirectory.
To build the Maven project site (the one you are just looking at right now), use:
This creates a directory target\site where all html files can be found that represent the documentation..
You can prepare the project for some IDEs like Eclipse or Netbeans.
To prepare a project for Eclipse, use:
This command creates all necessary files and folders used by Eclipse. The structure of your project (at root level) then looks like this:
my-app |- .settings |- src |- target |- .classpath |- .projekt `- pom.xml
The project can be imported to Eclipse directly with the dialog New - Project - Create project from existing source.
To clean the Eclipse specific files from the project, use:
When using CVS/SVN it is recommended, that you only upload a clean project structure, without any IDE specific files and folders.