Maven repository installation

1. Yesterday's content review The
mall project has been completed and will be reviewed in the actual combat of the project later.
Maven: Project management tool.
To manage the jar package, and to manage the project
JDK, the
Maven environment variable must be set up first : it cannot be placed directly on the C drive.
%MAVEN_HOME%\bin

Mirror configuration: jar packages are downloaded from the Internet to a local warehouse for use.
The central warehouse is outside the country, and the speed is particularly slow.
Generally, a domestic mirror server will be set up

Warehouse configuration: set the local warehouse location

2.maven-part1
2.1 Brief description and function (1)

Maven: It is an excellent project management tool.
Role:
project construction management (life cycle automation)
dependency management (for jar package management)
project information management

2.2 Environment setup (one-time configuration) (1)
2.2.1 Installation and configuration
Unzip the compressed package to the root directory of Disk D (note that it should be the root directory of a certain drive letter as much as possible, and the directory should not be deep)

As long as it is not the C drive (because the C drive has administrator rights, students who do not have administrator rights will cause various problems when maven updates the jar package.)

If there is no C drive, insert a U disk to save the maven
Insert picture description here
environment variable configuration:
1. JDK must first set up the environment (JAVA_HOME / PATH)
2. Maven environment variable (MAVEN_HOME/PATH)
3. Test: CMD window: mvn –v Check if there is any The version number appears.

Collection of classmate problems:
Win10: Ultimate and Professional versions are both allowed.
1. Run the mvn -v command without using the command line.
Win+R enter cmd and hit enter to enter the command line
2. maven_home adds a space in the path reference
Insert picture description here

3. Maven_home has an extra semicolon in the path reference. (The last key value of win10 cannot be added;)

Insert picture description here

Local warehouse: save all jar packages to be used locally. If there is no jar package locally, maven will automatically download it from the Internet. After the download is complete, it will be saved in the local warehouse.
Insert picture description here

If no local warehouse is set, maven automatically sets the local warehouse:
directory: user directory/.m2/repository
Insert picture description here
Insert picture description here

2.2.2 Idea's maven settings
Insert picture description here

2.2.3 Create a solution to the project stuck

Configuration information:

-DarchetypeCatalog=local,internal

2.3 Maven-idea project creation [phase focus]
2.3.1 create javaSE project (skeleton version creation)

Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here

If the project fails to build:
1. Check whether the maven environment is correctly configured to idea (if not configured, use the default idea that comes with the maven configuration. The built-in maven configuration is to access the old central warehouse, causing the access to fail: Bad Request 501)
Insert picture description here

2、本地仓库 jar包不完整导致 maven项目构建异常
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210122211900406.png)

使用脚本遍历本地仓库,发现不完整的jar包,就整体删除。
Maven若发现不完整jar包,导入/构建失败。
Maven若发现jar包不存在,重新下载。

Insert picture description here
Insert picture description here
3. Incomplete skeleton.
Insert picture description here

2.3.2 Create WEB project (creation of skeleton version)
Insert picture description here
Insert picture description here

Java directory: the previous src directory
Resource directory: store all the configuration files in the previous src directory
web.xml needs to be replaced with 4.0 Replace the
pom.xml file
Insert picture description here

The search here will give priority to the local warehouse. If the local warehouse is not available, download it from the central/mirrored warehouse on the external network

Insert picture description here
Insert picture description here

Web execution method 2:

Insert picture description here

Solution for tomcat cannot be deployed normally:
Insert picture description here

1. Declare the location of the front-end web root directory
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

2. Manually build war package dependencies
Insert picture description here

3. Maven- other knowledge
3.1maven warehouse (understand)
Insert picture description here

The Maven project will eventually import the jar package from the local warehouse.
If the jar package does not exist in the local warehouse, it will be downloaded from the external network to the local warehouse, and then the project will be imported from the local warehouse

Remote warehouse: A warehouse that needs to be connected via a network.
The central warehouse is a type of remote warehouse, but because there are no servers in the country and the access speed is slow, generally domestic users access the remote warehouses of Huawei Cloud and Alibaba Cloud.

When downloading a file from a remote warehouse, if the download is interrupted, the lastUpdated file will be left, which will cause the file to be incomplete and unable to be referenced and unable to download the latest jar package when it is used next time.
Cause a jar reference to fail.
Solution: clear the library script, clear it, and reopen the idea to download it.
If there is no setting to automatically download the jar package, you can manually download the jar package:
Insert picture description here

3.2 Maven's conceptual model (understanding)
There is a pom.xml file in each maven project, which defines the jar package that the project depends on, the coordinates of the project, and the package operation mode. (A maven project is a POM object)

依赖管理模型,管理jar包时,是根据jar包的坐标,来引入某个jar包的

从本地仓库导入jar包:
	Maven会先根据groupId在仓库中寻找文件夹(javax.activation) javax/activation
	Maven会再根据artifactId在当前文件夹中寻找项目名(activation)
	Maven最后根据version在当前文件夹中寻找版本号的目录(1.1)
	最终进入目录,导入jar包


若本地没有该jar包,从远程仓库进行加载,加载流程和本地仓流程一模一样。
找到jar包后,会把jar包下载到本地仓库,供maven引用。

若远程仓库也没有,最终maven报错。

In Jar package management, jar package management is performed according to the coordinates of the jar package.

The life cycle of the project: cleanup, initialization, compilation, testing, reporting, packaging, deployment, site generation
Maven automated operations: just click on the plug-in provided by maven

3.3maven coordinates

groupId: define the name of the current Maven project (we can understand it as the package name)
artifactId: define the project module (we can understand it as the project name)
version: define the current version of the current project

How to query the coordinates of a jar package:
https://mvnrepository.com/
Insert picture description here

Open detail
Insert picture description here
Insert picture description here

Copy the version coordinates directly to pom.xml
Insert picture description here

Note: The same coordinates cannot appear, otherwise an error will be reported.

Insert picture description here

If the automatic download fails: alt+insert, select update maven indices
will automatically update the local warehouse.
If the update fails, clear the database first, and then try this process.

3.4maven to create a custom WEB project (no skeleton creation, suitable for alternatives to web project creation failure) [Key]
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/xianyu120/article/details/113003063