1. Download maven
First of all, you need to know the download address of maven's official website : Maven – Download Apache Maven https://maven.apache.org/download.cgi
According to the official website, Maven 3.3+ require JDK 1.7 or above to execute
That is to say, java jdk must be installed before installing maven , and Maven 3.3+ and above versions need to be used with JDK 1.7 and above.
1. Select the zip version for the windows version (choose tar.gz for linux), as follows:
2. After downloading, unzip it directly in the directory to be installed (you can customize the directory), as follows:
2. Configure Maven environment variables
1. Right click on This PC and select Properties
2. Click System Advanced Settings--->Advanced--->Environment Variables--->New (System Variables)
3. Configure system variables:
Variable name (note case and underscore): MAVEN_HOME
Variable value (to be configured according to your own installation path): D:\Myself\Java\Maven\apache-maven-3.8.5
4. Edit the variable path Path (note capitalization and underscore):
%MAVEN_HOME%\bin
5. Click the OK button in turn to complete the configuration of the environment variables.
6. After completion, you can verify whether the installation and configuration are successful:
Press win+R to bring up the command line, enter cmd and press Enter
Enter the command: mvn -version and press Enter. If the following information appears, it means success.
3. Configure maven warehouse and related settings
1. First, build a maven-repository folder (maven warehouse) in the same directory as the maven installation
2. Find the settings.xml file in your maven installation path and open it:
3. Find the node <localRepository> and add your own maven warehouse address:
4. Configure mirroring (here uses Alibaba Cloud’s mirroring download dependency)
Also find the settings.xml configuration file, and add the following configuration between the <mirrors> and </mirrors> nodes:
<!-- 阿里云仓库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<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>
5. Configure JDK
Find the <profiles> node in the settings.xml configuration file and add the following configuration:
<!-- java jdk1.8版本 -->
<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>
6. Win+R to run cmd, input: mvn help:system and press Enter to test, the configuration will be successful and the following display will be displayed (the first execution of the mvn help:system command will take a while, because Maven will automatically help us to download the Maven Central Warehouse from the Maven Central Warehouse Update various configuration files and class libraries (jar packages) to the Maven local warehouse.):
4. Add maven to IDEA
Maven files are generally used together with IDEA. In order to allow you to select your own maven for each new project and avoid manually modifying the maven configuration every time, you can make the following adjustments:
Find setting in idea: