Maven (2): Maven download and configuration
foreword
This blogger will use CSDN to record the experience and knowledge he has personally gained and learned on the way to study software development. Interested friends can pay attention to the blogger! Perhaps a person can go fast alone, but a group of people can go farther!
1. Maven core program decompression and configuration
1. Maven official website address
⭕ Homepage:
⭕ Download page:
⭕ Download link:
2. Unzip the Maven core program
⭕ Core program compressed package:
apache-maven-3.8.6-bin.zip
, decompress to a non-Chinese directory without spaces.
⭕ In the decompression directory, we need to focus
Maven
on the core configuration file of :conf/settings.xml
3. Designate a local warehouse
The default value of the local warehouse: the user's home directory
/.m2/repository
. Since the default location of the local warehouse is in the user's home directory, and the home directory is often onC
the disk , that is, the system disk. In the future, there will be more and more packages inMaven
the warehousejar
, and the volume of the warehouse will become larger and larger, which may slow down the running speedC
of the disk and affect the system performance. Therefore, it is recommended toMaven
put the local warehouse under another drive letter. The configuration is as follows:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:\maven-repository</localRepository>
For the directory of the local warehouse, we can manually create an empty directory.
Remember: be sure to take the localRepository tag out of the comment.
Note: The local warehouse itself also needs to use a non-Chinese directory without spaces.
4. Configure the mirror warehouse provided by Alibaba Cloud
Maven
By default, the downloadjar
package accesses the overseas central warehouse, and the speed of foreign websites is very slow. Changing to the mirror warehouse provided by Alibaba Cloud and visiting the domestic website can make theMaven
downloadjar
speed of the package faster. The way to configure is:
4.1 Comment out the original example configuration
<!-- <mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror> -->
4.2 Add our configuration
Copy the whole of the following
mirror
tagsettings.xml
inside the mirrors tag of the file.
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
5. Configure the basic JDK version of the Maven project
If you run according to the default configuration, the default
JDK
version is1.5
, and the version we are familiar with and commonly used isJDK 1.8
the version . The way to modify the configuration is: copyprofile
the entire tagsettings.xml
toprofiles
the tag of the file.
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
2. Configure environment variables
1. Check whether the JAVA_HOME configuration is correct
Maven
is a program developed in the Java language, it must be run basedJDK
on , and needs toJAVA_HOME
find the installation locationJDK
of .
You can verify it with the following command:
C:\Users\Administrator>echo %JAVA_HOME%
D:\software\Java
C:\Users\Administrator>java -version
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
2. Configure MAVEN_HOME
TIP: Rules for configuring environment variables:
⭕
XXX_HOME
usually points to the upper level ofbin
the directory⭕
PATH
points tobin
the directory
3. Configure PATH
4. Verification
C:\Users\Administrator>mvn -v
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: D:\software\apache-maven-3.8.4
Java version: 1.8.0_141, vendor: Oracle Corporation, runtime: D:\software\Java\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"