一.配置Maven環境
1.下載apache-maven文件http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.zip
2.解壓1所下載文件,本人解壓到:/MyApplication/maven/apache-maven-3.5.33.配置Maven環境變量
open .bash_profile
添加以下內容並保存
#maven所在的目錄
export M2_HOME=/MyApplication/maven/apache-maven-3.5.3
#maven bin所在的目錄
export M2=$M2_HOME/bin
#將maven bin加到PATH變量中
export PATH=$M2:$PATH
二.修改Maven倉庫路徑
1、新建文件夾
創建文件夾 /MyApplication/maven/repository
創建文件 /MyApplication/maven/setting.xml
2、配置setting.xml
<?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 />
<localRepository>/MyApplication/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>
<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>
三.IntellIJ IDEA 中配置Maven
Idea 自帶了apache maven,默認使用的是內置maven,所以我們可以配置全局setting,來調整一下配置,比如遠程倉庫地址,本地編譯環境變量等。
打開 Idea 的Preferences(Settings)在輸入框輸入maven,編輯以下信息,點擊Apply-->OK
如果本地設置了MAVEN_OPTS 系統環境變量,這個步驟可以忽略
如果配置了本地apache-maven setting.xml 中的軟件源,這步驟可以忽略
點擊Apply-->OK 就完成了