mydomain
No ADS
No ADS

Maven Tutorial for Beginners

  1. Introduction
  2. Create Maven Project
  3. Configure Maven
  4. Installation Project with Maven
  5. Explain the operating principles of Maven
  6. View Local repository
  7. View Maven Repository on Internet
  8. Configuring Maven download source and javadoc
  9. Maven Manage Dependencies
  10. Build a multiple module project using maven

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

No ADS
In Eclipse, Click "New/Other"
Project is created.
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/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.o7planning</groupId>
   <artifactId>HelloMaven</artifactId>
   <version>0.0.1-SNAPSHOT</version>
</project>

3. Configure Maven

No ADS
Open pom.xml file to configure the library will use:
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/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.o7planning</groupId>
   <artifactId>HelloMaven</artifactId>
   <version>0.0.1-SNAPSHOT</version>

   <dependencies>
       <dependency>
           <groupId>org.apache.commons</groupId>
           <artifactId>commons-lang3</artifactId>
           <version>3.3.2</version>
       </dependency>
   </dependencies>
   
</project>
Create class CheckNumeric.java
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

No ADS
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.
  • You declare in pom.xml, that project depend on common-lang3 library version 3.3.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.
  • 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

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

7. View Maven Repository on Internet

No ADS
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
No ADS
No ADS