Maven learning entry stage summary

1. Introduction and characteristics of Maven

Maven is a project management tool that can help us build and depend on java projects.
Features (advantages):
1. Jar package management, separate jar package and project, reduce project volume.
A. Central warehouse to obtain jar package
B. Local warehouse management jar package

2. Cross-platform, which can be used on window, linux, mac.
3. One-click build project (tomcat:run command)

Two, obtain and configure Maven

1. Download from the official website
http://maven.apache.org/download.cgi
Insert picture description here
2. Configure local maven to
configure maven environment variables (you need to configure jdk first)
this computer -> properties -> advanced system properties -> environment variables ->
system Variable
A. Create a new MAVEN_HOME environment variable (variable value is your own installation path)
Insert picture description hereB. Configure maven in Path
Insert picture description here
C. Open cmd, enter mvn -v to view, the configuration is complete when maven information appears.
Insert picture description here

Three, Maven three warehouses

The three types of Maven warehouses are local warehouses, remote warehouses, and central warehouses.

1. Set up a local warehouse

View the location of the local warehouse
Open D:\apache-maven-3.6.3\conf\setting.xml (here is your own maven root directory –>conf –>setting.xml), you can see the default local warehouse location.
Insert picture description here
Find the repository file according to this path.
Insert picture description here
To facilitate reference management, set it to a convenient location. For example, I copied this package directly to the root directory of Disk D. After copying, remember to set the localRepository label in the setting to the changed path.
Insert picture description here
2. Set up the
Alibaba Cloud Maven warehouse mirror. Since the official website is a foreign website, the default is to go directly to the official website to search and download jar packages that are not available locally. It will be slower if you don’t have an agent. Therefore, an Alibaba Cloud Maven warehouse mirror is generally set up to facilitate Search for downloads.
The specific operation is as follows:
add the following mirror tag under mirrors in the settings.xml file

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

Just save the application.
3. Three kinds of warehouse connections
Insert picture description here

Four, Maven commonly used commands

1.mvn clean: clean up the directory generated after compilation;
2.mvn compile: compile the source code (only compile the main directory, not the code in the test);
3.mvn test-compile: compile the test code in the test directory;
4 .mvn test: run the test code in test;
5.mvn package: type the project into a jar package;
6.mvn install: publish the project to the local warehouse, that is, install the jar package in the local warehouse Repository;
7.mvn tomcat:run : One-click build project;

Five, the life cycle of Maven commands

Maven has three life cycles, and they are three independent life cycles.

1.Clean life cycle: clean;
2.Default life cycle: compile, test-compile, test, package, install
3. Site life cycle: site command, generate project report, site. Release site;
Features of the execution order of Maven commands:
1.
Only commands in the same life cycle are affected by the order of execution; 2. Command execution order in the Default life cycle:
compile --> test-compile -->test- ->package --> install, when a certain stage is run here, all previous stages will run automatically. That is, for example, running the install command, before the code will be compiled, run and packaged.

to sum up:

Let’s write so much for the introduction of Maven this time. After writing this article, I found that writing this kind of technical summary is really not easy. After all, the big guys have written too many good summaries, and I feel that how to write it is somewhat To repeat, there is really nothing I can output. After writing, I will write down a study note for myself, really pull my hips. Say goodbye to humble and end this article. . .
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43935558/article/details/107385026