Maven installation, environment variable configuration, local warehouse configuration and related error solutions

1. Maven installation and configuration environment variables (the picture shows windows 7, windows10 is the same)

#1 First, you should have downloaded and installed the JDK and configured the environment variables

#2 Search Maven in the browser, enter Maven's official website to download and unzip it (currently the latest version is apache-maven-3.6.0-bin.zip)

Mine is in the E:\maven directory
#3 Then configure the environment variable, create a new environment variable MAVEN_HOME and assign a value. The variable value is the address of your installation.
(My installation path is E:\maven\apache-maven-3.6.0)

insert image description here
#4 Update the Path value, edit the environment variable Path under windows 7, and append the variable value;%MAVEN_HOME%\bin
(update the Path under windows10, and create a new variable value %MAVEN_HOME%\bin)
(The windows7 shown in the picture is the encounter mentioned below to the case of incorrectly modifying the value of a variable)

insert image description here

#5 Verify whether it is successful, enter mvn -version in cmd, if you see the picture below, it is correct

insert image description here

What went wrong:

If the following error conditions occur

insert image description here

solution

This may be because the original variable was overwritten when setting the environment variable Path, just change the original ;%MAVEN_HOME%\bin to ;%SystemRoot%\system32;%maven_home%\bin after the path and repeat #5 to check whether it is
successful .

2. Configure the Maven local warehouse (beginners can also use the default warehouse, which is in C:)

  1. Create a new maven-repository folder under E:, which is used as maven's local warehouse.

  2. Open the E:\maven\conf\settings.xml file, find the localRepository tag, find the following line of code and modify the middle content to:

      <localRepository>E:/maven-repository</localRepository>
    

insert image description here

  1. The localRepository node is used to configure the local warehouse. The local warehouse actually acts as a cache. Its default address is C:\Users\username.m2.

insert image description here
When we get the jar package from maven, maven will first search in the local warehouse, and return if the local warehouse has it; if not, get the package from the remote warehouse and save it in the local warehouse.

In addition, we run mvn install in the maven project, and the project will be automatically packaged and installed in the local warehouse.

  1. Run the DOS command mvn help:system
    if the previous configuration is successful as shown in the figure below
    insert image description here

Notice

If you have not modified the local warehouse, run the DOS command mvn help:system and the following error will appear.
insert image description here
Solution:
add the bottom <mirror code under the mirror in E:\maven\conf\settings.xml.
insert image description here
The above is the summary of my study and the errors and solutions I encountered. I hope it can help everyone. If you have any questions, you can comment and we can solve them together!

Guess you like

Origin blog.csdn.net/qq_41238751/article/details/86260507