English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven Tutorial

This tutorial is prepared for beginners to help them understand the basic functions of the Maven tool. After completing this tutorial, you will find that you have an intermediate level of expertise in using Apache Maven, from which you can enter higher levels.

Maven is translated as 'expert' or 'insider' and is an open-source project developed purely in Java under Apache. Based on the concept of Project Object Model (abbreviation: POM), Maven uses a central information snippet to manage a project's construction, reports, and documentation steps.

Maven is a project management tool that can build and manage Java projects.

Maven can also be used to build and manage various types of projects, such as C#, Ruby, Scala, and other language-based projects. Maven was once a subproject of the Jakarta project and is now an independent Apache project hosted by the Apache Software Foundation.

Knowledge you need to understand before reading this tutorial

This tutorial is mainly aimed at beginners to help them learn the basic functions of the Maven tool. After completing this tutorial, your Apache Maven expertise will reach an intermediate level, and then you can learn more advanced knowledge.

To read this tutorial, you need the following basics:Java Basics.

Maven Functions

Maven can help developers complete the following tasks:

  • Build

  • Document generation

  • Reports

  • Dependencies

  • SCMs

  • Release

  • Distribution

  • Mailing list

Conventional configuration

Maven advocates the use of a common standard directory structure. Maven follows the principle of convention over configuration, and everyone is encouraged to adhere to such a directory structure. As shown below:

DirectoryPurpose
${basedir}Stores pom.xml and all subdirectories
${basedir}/src/main/javaThe project's Java source code
${basedir}/src/main/resourcesThe project's resources, such as property files, springmvc.xml
${basedir}/src/test/javaThe project's test classes, such as JUnit code
${basedir}/src/test/resourcesTest resources
${basedir}/src/main/webapp/WEB-INFWeb application file directory, web project information, such as storing web.xml, local images, jsp view pages
${basedir}/targetPackaging output directory
${basedir}/target/classesCompilation output directory
${basedir}/target/test-classesTest compilation output directory
Test.javaMaven will only automatically run test classes that comply with the naming rules.
~/.m2/repositoryThe default local repository directory location of Maven

Maven Features

  • Project settings follow unified rules.

  • Shared in any project.

  • Dependency management includes automatic updates.

  • A vast and continuously growing library.

  • Extensible, easy to write plugins in Java or scripting languages.

  • Access new features with little or no additional configuration.

  • Model-Based Building − Maven can build any number of projects into predefined output types, such as JAR, WAR, or distributions based on project metadata, without needing to execute any scripts in most cases.

  • Consistent Site for Project Information − Using the same metadata as the build process, Maven can generate a website or PDF, including any documentation you want to add, and add it to standard reports on the status of project development.

  • Release Management and Publishing Individual Outputs − Maven can be integrated with source code management systems (such as Subversion or Git) without additional configuration and can manage project releases based on a tag. It can also distribute its releases to distribution locations for use by other projects. Maven can publish individual outputs, such as JARs, containing other dependencies and archives of documents, or as source code releases.

  • Backward Compatibility − You can easily migrate from multiple modules of old versions of Maven 3 in.

  • When a subproject uses dependencies from a parent project, normally the subproject should inherit the parent project dependencies without using version numbers,

  • Parallel Building − Compilation speed can be generally improved20 - 50 %.

  • Better Error Reporting − Maven improved error reporting by providing links to Maven wiki pages where you can click to view the full description of the error.

    Apache Maven is a software project management and comprehension tool. Based on the concept of Project Object Model (POM), Maven can manage the construction, reporting, and documentation of projects from a central information hub. Using Maven, we can build and manage any Java-based project. This tutorial will teach you how to use Maven in your daily work when developing any project with Java.