Hello Maven
This Tutorial will show you how to download and install Maven - an open source build tool.
Main Learning's
After following this tutorial you will learn how to:
- Download and install Maven
- Set up the required Maven System Variables
- Verify that the Maven is properly installed
- Create, Compile and package a HelloMaven project
Versions used:
- OS: Windows XP V1.6
- JDK version 1.6.0_3
- Maven version 2.0.8
Assumptions:
The JDK is properly installed
Tutorial Steps:
- Go to the Maven download page at: http://maven.apache.org/download.html
- Download maven binary distribution file – e.g. apache-maven-2.0.8-bin.zip
- Unzip and install maven (e.g. C:\Program Files\Apache Software Foundation\apache-maven-2.0.8)
- Set the MAVEN_HOME environment variable to the directory where you installed Maven.
- On Windows: Systems Properties/ Advanced/ Environment Variables / System Variables/ New


- Add the Maven bin directory to your path.


- Make sure the jdk is properly installed – Maven uses Java, therefore the JDK must be properly installed.
- Make sure maven is working.
- Open a command prompt and execute mvn –help

- Create a folder for your hello world maven project – e.g. C:\codebase\sample\hellomaven
- on the hellomaven/ folder, execute the following command:
- mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mypackage -DartifactId=my-hellomaven
- You should get the results as depicted in the following picture

- A package structure and files have been created for your project:

- A directory named my-hellomaven has been created for the new project, and this directory contains a file named pom.xml, that should look like this:
-
<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.mypackage</groupId>
<artifactId>my-hellomaven</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-hellomaven</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>
- Compile your project
- From the my-hellomaven folder, execute the following command:
- mvn compile

- Now try running your project tests by executing:
- mvn test

- For creating a jar file, execute
- mvn package

- Check out the generated contents at my-hellomaven/target folder.

17. Generating Integrated Development Environment (IDE) Project files
To generate the files needed for an IntelliJ IDEA Project setup, you only need to execute the main plugin goal, which is idea:idea like so:
mvn idea:idea
Similarly, To generate the files needed for an Eclipse Project setup, you only need to execute the main plugin goal, which is eclipse:eclipse like so:
mvn eclipse:eclipse
Comments (0)
You don't have permission to comment on this page.