Maven Tutorial
Maven is translated as "expert" or "insider" [in Chinese] and 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 steps such as a project's build, reporting, and documentation.
Maven is a project management tool that can build and manage dependencies 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 subproject of the Jakarta project and is now an independent Apache project hosted by the Apache Software Foundation.
Knowledge you need 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 professional knowledge of Apache Maven will reach an intermediate level, and then you can learn more advanced knowledge.
To read this tutorial, you need the following foundation:Java Basics。
Maven Features
Maven can help developers accomplish the following tasks:
- Build
- Documentation generation
- Reporting
- Dependencies
- SCMs
- Release
- Distribution
- Mailing lists
Maven Characteristics
Convention over Configuration: Provides standardized project structure and build lifecycle
Dependency Management: Automatically handles project dependency relationships
Plugin System: Rich plugins support various build tasks
Multi-module Support: Simplifies 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; 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 | Project's Java source code |
| ${basedir}/src/main/resources | Project resources, such as property files, springmvc.xml |
| ${basedir}/src/test/java | Project test classes, such as JUnit code |
| ${basedir}/src/test/resources | Test resources |
| ${basedir}/src/main/webapp/WEB-INF | Web application file directory, web project information, such as web.xml, local images, JSP view pages |
| ${basedir}/target | Packaging output directory |
| ${basedir}/target/classes | Compilation output directory |
| ${basedir}/target/test-classes | Test compilation output directory |
| Test.java | Maven will only automatically run test classes that conform to this naming convention |
| ~/.m2/repository | Maven's default local repository directory location |