Maven Tutorial for Beginners

View more Tutorials:

Websites to learn foreign languages for free:
Follow us on our fanpages to receive notifications every time there are new articles. Facebook Twitter

1- Introduction

We must first ensure that you have installed Maven into Eclipse. If not, you can see the installation instructions here:
The goal of the tutorial:
This is the image after Project completion:

2- Create Maven Project

In Eclipse, Click "New/Other"
Project is created.

<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/xsd/maven-4.0.0.xsd">

3- Configure Maven

Open pom.xml file to configure the library will use:

<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/xsd/maven-4.0.0.xsd">

Create class CheckNumeric.java

package org.o7planning.tutorial.hellomaven;

import org.apache.commons.lang3.StringUtils;

public class CheckNumeric {

  public static void main(String[] args) {
      String text1 = "0123a4";
      String text2 = "01234";
      boolean result1 = StringUtils.isNumeric(text1);
      boolean result2 = StringUtils.isNumeric(text2);

      System.out.println(text1 + " is a numeric? " + result1);
      System.out.println(text2 + " is a numeric? " + result2);


Running CheckNumeric class and get results:
You can clearly see your project using the library. Where is its location on the hard drive.

4- Installation Project with Maven

The nature here is compile and pack your Project by Maven:

5- Explain the operating principles of Maven

Above you have created the project and ran flawlessly. The Project using StringUtils class, which to be a class of Apache, and not in the standard library of JDK. Traditionally you have to copy this library to project and declare the classpath.

However, the guidelines do not have to copy and declare classpath as the traditional way. The library was managed by Maven management. Now we will explain how Maven works:
The illustration above shows how the Maven done.
  1. You declare in pom.xml, that project depend on common-lang3 library version 3.3.2.
  2.  As soon as you SAVE pom.xml file, Maven will check if this library has local repository on your computer yet. If has no, Maven will download it from the repository in the internet.
  3.  Finally, Maven will automatically declare Classpath.
So you only need to declare all libraries want to use in pom.xml. The libraries was managed by Maven.

6- View Local repository

Your question is where local repository located?
View your project is packed to the Local Repository:

7- View Maven Repository on Internet

The question is where to lookup the information groupId, artifactId and version.
You can go to one of these sites:

8- Configuring Maven download source and javadoc

Normally Maven only download binary files.  To Maven download the source and javadoc, you need to configure on Eclipse.
  • Windows/Preferences
Change something in the pom.xml file and save (Or build project), Maven will download the source and javadoc.
The results you see on the Local Repository:

9- Maven Manage Dependencies

10- Build a multiple module project using maven

Next you can learn how build a multiple module project with maven

View more Tutorials: