Maven Tutorial
Maven is translated as "expert" and "connoisseur"; it is a pure Java open-source project under Apache. Based on the concept of the Project Object Model (abbreviation: POM), Maven uses a central piece of information to manage steps such as a project's build, reporting, and documentation.
Maven is a project management tool that can build Java projects and manage dependencies.
Maven can also be used to build and manage various projects, such as those 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.
What you need to know before reading this tutorial
This tutorial is mainly aimed at beginners, helping them learn the basic functions of the Maven tool. After completing this tutorial, your Apache Maven expertise will reach an intermediate level, after which you can learn more advanced knowledge.
To read this tutorial, you need to have the following foundation:Java Fundamentals。
Maven Features
Maven can help developers accomplish the following:
- Build
- Documentation generation
- Reporting
- Depends on
- SCMs
- Release
- Distribution
- Mailing lists
Maven Characteristics
-
Convention over configuration: provides a standardized project structure and build lifecycle
-
Dependency Management: automatically handles project dependencies
-
Plugin system: rich plugins support various build tasks
-
Multi-module support: simplifies the management of large projects
-
Central repository: access globally shared library resources
Convention Configuration
Maven advocates using a common standard directory structure. Maven uses the principle of convention over configuration, and everyone should follow this directory structure as much as possible. It is shown below:
| directory | Purpose |
|---|---|
| ${basedir} | Stores pom.xml and all subdirectories |
| ${basedir}/src/main/java | The project's Java source code |
| ${basedir}/src/main/resources | The project's resources, such as property files, springmvc.xml |
| ${basedir}/src/test/java | The project's test classes, such as JUnit code |
| ${basedir}/src/test/resources | Resources for testing |
| ${basedir}/src/main/webapp/WEB-INF | Web application file directory, web project information, such as storing web.xml, local images, and JSP view pages |
| ${basedir}/target | Packaging output directory |
| ${basedir}/target/classes | Compiled output directory |
| ${basedir}/target/test-classes | Test compiled output directory |
| Test.java | Maven only automatically runs test classes that follow this naming convention |
| ~/.m2/repository | Maven's default local repository directory location |