Article Directory
Maven overview
maven is a project management tool
The main role of maven is:
- Maven builds the project into modules to improve development efficiency
- 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
- 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:
-
Central warehouse : a server that stores all commonly used jars, open to the outside world, maintained by a professional team, address: https://mvnrepository.com/
-
Remote warehouse (private service): Generally, the enterprise puts the core jar package on its own server (such as Ali mirroring)
-
Local warehouse : jar packages and plug-ins are stored locally (that is, stored in a folder on your computer's hard drive)
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
- Setting
MAVEN_HOME
is the path where your maven is located
- Add Path environment variable:
%MAVEN_HOME%\bin
(Path add%MAVEN_HOME%\bin)
- windows+r, enter cmd to open the DOS window and enter to
mvn -v
view your maven version information
Configure maven local warehouse
conf/settings.xml
Configure 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)
Configure maven mirror/remote warehouse (here configure Alibaba Cloud mirror)
In conf/settings.xml
about 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>
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. |