Maven Tutorial

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

Maven is a project management tool that can perform build and dependency management for Java projects.

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


Prerequisites for reading this tutorial

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

To read this tutorial, you need to have the following foundation:Java basics。


Maven Features

Maven can help developers accomplish the following tasks:

  • Build
  • Documentation generation
  • Reporting
  • Dependencies
  • SCMs
  • Release
  • Distribution
  • Mailing list

Maven Characteristics

  1. Convention over Configuration: provides standardized project structure and build lifecycle

  2. Dependency management: automatically handles project dependencies

  3. Plugin system: rich plugin support for various build tasks

  4. Multi-module support: simplifies management of large projects

  5. Central repository: access to globally shared library resources


Convention Configuration

Maven advocates using a common standard directory structure. Maven follows the principle of convention over configuration, and everyone should follow such a directory structure as much as possible. As shown below:

Directory Purpose
${basedir} Stores pom.xml and all subdirectories
${basedir}/src/main/java Java source code of the project
${basedir}/src/main/resources Project resources, such as property files, springmvc.xml
${basedir}/src/test/java Test classes of the project, such as JUnit code
${basedir}/src/test/resources Resources for testing
${basedir}/src/main/webapp/WEB-INF Web application file directory; stores web project information, such as web.xml, local images, JSP view pages
${basedir}/target Package output directory
${basedir}/target/classes Compiled output directory
${basedir}/target/test-classes Test compilation output directory
Test.java Maven will only automatically run test classes that conform to this naming rule
~/.m2/repository Maven's default local repository directory location
Other extensions