Install Maven and configure Maven in idea

Time:2021-4-17

step

1. Download Apache maven

1.1 official website

Old version download location

Click this link →http://maven.apache.org/download.cgi, and then click the blue hyperlink “Maven releases history” in the figure below
 
 
Or visit this link directly:http://maven.apache.org/docs/history.html

Install Maven and configure Maven in idea

1.2 Baidu cloud

See this article →Configuring Apache Maven 3.6.1

 
 
 

2. Unzip the Maven downloaded just now to a path

Try not to have Chinese or spaces in the path

thereD:\mySoftware\javaweb\apache-maven-3.6.1It’s the Maven root path

Install Maven and configure Maven in idea

 
 
 

3. Configure Windows environment variables

3.1 preparation

First, make sure that the JDK version is above 1.8
 
 
Enter the following command in CMD

java -version

Install Maven and configure Maven in idea

3.2 configure maven_ Variable value of home

Install Maven and configure Maven in idea
Install Maven and configure Maven in idea
Install Maven and configure Maven in idea
Install Maven and configure Maven in idea

 
 
Variable name: maven_ HOME
Variable value (Maven root path): D: \% mysoftware \ \% JavaWeb \ \% apache-maven-3.6.1

Install Maven and configure Maven in idea
Install Maven and configure Maven in idea

 
 
 

3.3 configuration of test environment variables

To query the Maven version and Java version, enter the command in CMDmvn -v

 

4. Maven related configuration (such as local warehouse, settings.xml (Revised)

4.1 create a new folder repository to store the jar packages automatically downloaded by Maven

For example, I create a new folder in the Maven root directorymyrepository. (folder name and location are optional)

 
 
Note: this folder is not necessary. By default, there is a. M2 / repository directory on disk C. the capacity of Disk C is limited, so I define a folder to store the jar package automatically downloaded by Maven

Install Maven and configure Maven in idea

4.2 (non essential) backup settings.xml file

Copy the settings.xml , change the new file name tosettingsBackup.xml, the name is optional, mainly backup
Install Maven and configure Maven in idea

 
 
 

4.3 modify the original settings.xml file

Open with a text editor settings.xml File to configure. The content after configuration is as follows:
(there are some comments in the file, which can be deleted. When configuring, see clearly. Do not edit in the comment label to avoid invalidation.)

In general, you just need to add<localRepository>D:/server/maven/repository</localRepository>
as well as<mirrors>All in<mirror>Label is enough.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
    <pluginGroups />
    <proxies />
    <servers />
    
    <! -- the jar package automatically downloaded by Maven will be stored in this directory -- >
    <localRepository>D:/server/maven/repository</localRepository>
    
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
        </mirror>
        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <! -- mirror image of central warehouse in China
        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
    
</settings>

 
 
 

5. Configure Maven in idea

5.1 open the settings panel

Note: you can close the current project and open settings in the initial panel of idea.This article
The authors say it can be applied to global configuration.

Install Maven and configure Maven in idea

Install Maven and configure Maven in idea

 
 
 

But I tried and found that every time I create a new project, I still need to change it manually. After a search, we found that:This articleThe author said:

After the version of idea2018, default setting has disappeared and has become setting for new project.

 
 
 
So in fact, the next time or to set up a.. I haven’t found a solution yet. Sorry.
 
 
 

5.2 configuration

1) Red box in configuration diagram (please choose your own path)

And check override

Install Maven and configure Maven in idea

 
 
VM Options:-Xms128m -Xmx512m -Duser.language=zh -Dfile.encoding=UTF-8

JRE:Use JAVA_HOME
Install Maven and configure Maven in idea

 
 

(in fact, these two links are settings.xml I think that if settings.xml Yes, it should not be added)

http://maven.aliyun.com/nexus…
http://maven.aliyun.com/nexus…

Install Maven and configure Maven in idea

 
 
Add: there are two more configurations that can be added

The purpose is as follows:

It can be imported automatically porm.xml The dependence in the game. When the dependency changes, it is imported automatically.

Install Maven and configure Maven in idea

 
 
Modify character set
Please refer to this article for detailsDefault global settings of idea

Install Maven and configure Maven in idea

 
 
 

5.3 testing

Open a local project and click the arrow in the figure below. Test whether the relevant jar package can be downloaded
Install Maven and configure Maven in idea
 
 

Open your new myrepository folder and check the download status
Install Maven and configure Maven in idea
 
 
 

reference resources

Configuring Apache Maven 3.6.1

IntelliJ idea configures Maven and modifies the default repository

IntelliJ idea configures Maven and modifies the default repository

Idea global permanent default settings after 2018

Default global settings of idea

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]