Maven Detailed Explanation-Coordinate Properties-Environment Variable Configuration-Configuration Mirror-Configure Local Warehouse-Scope Value

Maven overview

  maven is a project management tool

  The main role of maven is:

  1. Maven builds the project into modules to improve development efficiency
  2. Maven can manage the jar package of the project in a unified way , without having to copy and import the jar package for each module, it can be automatically imported using the configuration file
  3. Maven can provide one-stop service for your project from writing code to launching : initialization, compilation, testing, reporting, packaging, deployment, and cleaning

Maven repository

  The Maven warehouse is the place to store the jar packages and plugins used by the project

Maven warehouse classification:

  1. Central warehouse : a server that stores all commonly used jars, open to the outside world, maintained by a professional team, address: https://mvnrepository.com/

  2. Remote warehouse (private service): Generally, the enterprise puts the core jar package on its own server (such as Ali mirroring)

  3. Local warehouse : jar packages and plug-ins are stored locally (that is, stored in a folder on your computer's hard drive)
    Insert picture description here

Because the central warehouse is abroad, access is relatively slow, so we generally do not download jar packages from remote warehouses, but use domestic mirrors (remote warehouses) to download the required jar packages.
When the project is used, first search from the local warehouse and use it directly if found, download it from the remote warehouse (or central warehouse) to the local library if not found, and then obtain it from the local library

The coordinates of the Maven warehouse (distinguish the jar identification method)

  There are many jar packages in the maven warehouse. If we find the jar packages we need, we need to set an identifier for each jar package, namely the coordinates

Coordinate properties :

Attribute value description
groupId The name of the project or organization is usually the reverse of the company domain name (com.baidu, com.alibaba
artifactId module module name
version Version number SNAPSHOT unstable version, RELEASE is the stable version (default value is: 1.0.1-SNAPSHOT)

Maven installation and use

Download and install address: http://maven.apache.org/download.cgi

Set Maven environment variables

  1. Setting MAVEN_HOMEis the path where your maven is located
    Insert picture description here
  2. Add Path environment variable: %MAVEN_HOME%\bin(Path add%MAVEN_HOME%\bin)
    Insert picture description here
  3. windows+r, enter cmd to open the DOS window and enter to mvn -vview your maven version information
    Insert picture description here

Configure maven local warehouse

conf/settings.xmlConfigure the local warehouse path
in   the file under the maven directory. Add this statement after line 54 <localRepository>E:/repository</localRepository>(E:/repository is the storage location of your local warehouse)
Insert picture description here

Configure maven mirror/remote warehouse (here configure Alibaba Cloud mirror)

  In conf/settings.xmlabout 159 files add tags back row, enter the following content is

	<mirror>
		 <id>alimaven</id>
		 <mirrorOf>central</mirrorOf>
		 <name>aliyun maven</name>
		 <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
	</mirror>

Insert picture description here

The scope of the jar package in Maven

When importing dependencies , there is a scope attribute (mainly managing the deployment of dependencies), which has the following values:

scope attribute description
test Use only when testing (junit @Test)
provided Compile, test use , without runtime (** running on the server when I do not take this jar package to the server - because of this jar package on the server, if the upload, it will have the same name appear jar) [such as servlet .jar]-the dependency will not be loaded when packaging
runtime Applicable to run and test phases (such as JDBC driver), load the dependency at runtime, not at compile time
compile The default value is used for compiling, testing and running (the jar package will be brought to the server during runtime )
system Similar to provided, you need to explicitly provide the jar that contains the dependencies, and Maven will not look for it in the Repository.

Directory structure of Maven project

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40542534/article/details/108725852