Article directory
![insert image description here](https://img-blog.csdnimg.cn/60c5ad2833664d43881bee2b7a2a016c.gif#pic_center)
1. Introduction to Maven
Maven is a Java project management tool and build tool for managing project dependencies, build process, and project deployment. It is an open source project of the Apache Software Foundation. The essence of Maven is a project management tool that abstracts the project development and management process into a project object model (POM)
Note: POM (Project Object Model): project object model
Using Maven can simplify the construction process of the project and provide a unified project structure and construction configuration method. By defining a file describing the project structure and dependencies pom.xml
, Maven can automatically download and manage the dependent libraries required by the project, and can perform a series of construction tasks such as compilation, testing, packaging, and deployment.
2. Download Maven
Although IDEA comes with Maven, the default path is on the C drive. The path is: C:\Users\用户名\.m2
under the directory
Maven download address: https://maven.apache.org/
3. Maven environment configuration
Depends on Java, needs to be configured JAVA_HOME
To set up MAVEN's own operating environment, needs to be configuredMAVEN_HOME
Copy where Maven is located
Configure system variables
And configure to add in Path%MAVEB_HOME%\bin
4. The basic concept of Maven
Maven has three basic concepts: warehouse, coordinates and warehouse configuration
4.1 Warehouse
Warehouse: used to store resources, including various jar packages
Warehouse classification :
- Local warehouse: a warehouse that stores resources on your own computer, and connects to a remote warehouse to obtain resources
- Remote warehouse: a warehouse on a non-local computer that provides resources for the local warehouse
Remote warehouses are also divided into two types:
- Central warehouse: Maven team maintains and stores all resource warehouses
- Private server: a department/company-wide warehouse that stores resources and obtains resources from the central warehouse
The role of private servers:
to preserve copyrighted resources, including purchased or self-developed jars.
The jars in the central warehouse are all open source and cannot store copyrighted resources.
Resources are shared within a certain range and are only open to the inside and not shared externally.
4.2 Coordinates
Coordinates in Maven are used to describe the location of resources in a repository
The main components of Maven coordinates are:
-
groupld
: Define the name of the organization to which the current Maven project belongs (usually the domain name is reversed, for example: org.mybatis) -
artifactld
: Define the current Maven project name (usually the module name, such as CRM, SMS) -
version
: Define the current project version number -
packaging
: Define the packaging method of the project (war/jar)
One of Maven's features is dependency management: by configuring the dependencies in the pom.xml file, Maven can automatically download and manage the dependent libraries required by the project. It can get dependencies from Maven central warehouse or other remote warehouses.
Maven central warehouse address: Maven Repository: Search/Browse/Explore (mvnrepository.com)
The role of Maven coordinates: use a unique identifier to uniquely locate the resource location. Through this identifier, the identification and download of resources can be completed by the machine
4.3 Warehouse configuration (modify IDEA default Maven library)
Maven's warehouse is by default in C:/Users/用户/.m2/repository
the directory. And this directory is usually under the C drive, it is best not to put it on the C drive
repository
You can create a Maven directory where you want, and create a directory in the Maven directory
Find the Maven configuration file in the downloaded Maven.
You can use an editor to open it. I use VScode here.
In addition to the above places that need to be modified, the location of the central warehouse must also be changed (the Maven central warehouse is abroad, and domestic access will be very slow) , which can be used 阿里云镜像仓库
, which is faster since importing
<mirror>
<!-- 此镜像的唯一标识符,用来区分不同的mirror元素-->
<id>nexus-aliyun</id>
<!--对哪种仓库进行镜像,简单说就是替代哪个仓库-->
<mirrorOf>central</mirrorOf>
<!--镜像名称-->
<name>Nexus aliyun</name>
<!--镜像URL -->
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
Modify IDEA's Maven library
Open IDEA settings, find Maven
and complete the changes.