[Maven] Maven download, configuration and basic concepts


insert image description here

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\用户名\.m2under the directory

Maven download address: https://maven.apache.org/

insert image description here

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
insert image description here

Copy where Maven is located
insert image description here
Configure system variables

insert image description here

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 :

  1. Local warehouse: a warehouse that stores resources on your own computer, and connects to a remote warehouse to obtain resources
  2. Remote warehouse: a warehouse on a non-local computer that provides resources for the local warehouse

Remote warehouses are also divided into two types:

  1. Central warehouse: Maven team maintains and stores all resource warehouses
  2. 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/repositorythe directory. And this directory is usually under the C drive, it is best not to put it on the C drive

repositoryYou 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.
insert image description here
You can use an editor to open it. I use VScode here.
insert image description 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
insert image description here
and complete the changes.

insert image description here

Guess you like

Origin blog.csdn.net/m0_63463510/article/details/131756224