Maven Tutorial in 7 Minutes


Maven is a project management tool which makes it easy to manage :
-> Builds
-> Dependencies
-> Documentation
-> Reporting
-> Releases
-> Distribution etc

Before moving further , lets look at some terminology used in Maven.

Maven Terminology

Project Object Model (POM) : It is the meta data or configuration file ( pom.xml ) for Maven Project. It is located in root directory of each maven project.

Artifact : It is something that is produced or used by the Maven project. Examples are JARs, Source and Binary distributions and WARs. Each artifact is uniquely identified by its groupID and artifactID which is unique within group.

GroupId : A group ID is a universally unique identifier for a project.

Dependency : Dependencies are libraries such as JAR artifacts which are used by Project.

Plug-in and Goal : Every piece of functionality in Maven is provided by a plug-in. Plug-in contains Goals ( which can be thought of as tasks ) and uses meta data provided in POM to perform their tasks.

Repository : It is used to hold artifacts or dependencies of projects. There are two types of repositories in Maven which are 1) Local Repository ( which is folder on your local computer ) 2) Remote Repository

Now lets get into practicals :

Step 1) Install Maven
Step 2) Basic Example on creating a project with Maven
Step 3) Basic Operations of Maven

Install Maven

Here is the 2-Step Maven Installation which you can complete in a minute.

Basic Example on creating a project with Maven

Open Command Prompt and change current directory to some other directory of your choice where created project will be stored.

For Example :

Type the following command ( with given parameters ) and press Enter

Command Explained :

mvn                                          =    Maven Command
archetype                                 =    Plugin provided by Maven
generate                                   =    Goal in ‘archetype’ plugin ( generates the project based on the given template )
-D………..                                    =    these are the parameters to the goal ‘generate’
maven-archetype-quickstart    =    Template provided by Maven

Since you are running this command for the first time, based on your network connection speed it takes some time for downloading the required artifacts of maven into the local repository. At the End, it stops with the following output.

This will create the project with following Standard Directory Structure.

Basic-Example-by-CodeForEach Folder Structure

Basic Operations of Maven

Lets look at three basic operations : compiling, creating the jar for above project and creating a documentation site for the project.

First you need to change the current directory to the created project folder.

1) Compile the Project

command : mvn compile

This will compile the project ( only main source files )

Output files location : target/classes

2) Build the Project

command : mvn package

This will build( creates either jar or war file which depends on the packaging info provided in POM ) the project .

For above project we created, it generates a jar file since package value is jar in POM ( pom.xml ) of the project.

Output file location : target/<jar file>

3) Create a Documentation Site

command : mvn site

This operation creates a site for the project based upon the information provided in the POM.

Output files location : target/site


References :



Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">