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:

Maven – Welcome to Apache Maven(opens new window)

⭕ Download page:

Maven – Download Apache Maven

⭕ Download link:

insert image description here

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 Mavenon 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 on Cthe disk , that is, the system disk. In the future, there will be more and more packages in Maventhe warehouse jar, and the volume of the warehouse will become larger and larger, which may slow down the running speed Cof the disk and affect the system performance. Therefore, it is recommended to Mavenput 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

MavenBy default, the download jarpackage 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 the Mavendownload jarspeed 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 mirrortag settings.xmlinside 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 JDKversion is 1.5, and the version we are familiar with and commonly used is JDK 1.8the version . The way to modify the configuration is: copy profilethe entire tag settings.xmlto profilesthe 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

Mavenis a program developed in the Java language, it must be run based JDKon , and needs to JAVA_HOMEfind the installation location JDKof .

insert image description here

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

insert image description here

TIP: Rules for configuring environment variables:

XXX_HOMEusually points to the upper level of binthe directory

PATHpoints to binthe directory

3. Configure PATH

insert image description here

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"

Guess you like

Origin blog.csdn.net/weixin_52533007/article/details/125323736