一、前提條件
下載並安裝好JDK 。在終端輸入命令“java -version”,如果出現類似如下信息說明JDK安裝成功。
二、開始配置Maven
1. 下載maven:http://mirror.bit.edu.cn/apache/maven/maven-3/
# 使用wget命令在線下載,現在前必須確保wget已安裝,否則yum install wget wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz # 解壓 tar -zxvf apache-maven-3.2.5-bin.tar.gz # 移動並改名 mv apache-maven-3.2.5 /usr/local/maven3
2. 設置環境變量
vi /etc/profile
在/etc/profile中添加以下幾行:
export MAVEN_HOME=/usr/local/maven3 export PATH=$MAVEN_HOME/bin:$PATH
執行source /etc/profile使環境變量生效:
source /etc/profile
最后運行mvn -v驗證maven是否安裝成功,如果安裝成功會打印如下內容:
mvn -v
三、建立maven倉庫
1. 建立一個文件夾,假設路徑為: /usr/local/maven_repository。
2. 打開 /usr/local/maven3/conf/setting.xml 文件,設置我們的倉庫路徑:
<!-- 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>/usr/local/maven_repository</localRepository>
3. 配置鏡像
<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</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>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>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>nexus-pentaho</id> <mirrorOf>central</mirrorOf> <name>Nexus pentaho</name> <url>https://nexus.pentaho.org/content/repositories/omni/</url> </mirror>