溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

centos6.x中如何安裝maven

發(fā)布時間:2021-07-19 14:37:19 來源:億速云 閱讀:158 作者:小新 欄目:系統(tǒng)運維

這篇文章主要介紹了centos6.x中如何安裝maven,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

centos6.x下安裝maven

1.下載maven包

首先從官網(wǎng)上 http://maven.apache.org/ 下載最新版Maven。

本人下載包為apache-maven-3.2.1-bin.tar.gz

centos6.x中如何安裝maven

2.減壓maven包

執(zhí)行tar -zxvf apache-maven-3.2.1-bin.tar.gz

centos6.x中如何安裝maven

下圖為減壓成功頁面

centos6.x中如何安裝maven

3.放在期望目錄下(可選)

把減壓好的文件放在/opt目錄下

執(zhí)行sudo mv apache-maven-3.2.1 /opt

centos6.x中如何安裝maven

4.更改鏈接

執(zhí)行  ln -s apache-maven-3.2.1  apache-maven

centos6.x中如何安裝maven

5.配置環(huán)境變量

centos6.x中如何安裝maven

6.改動生效

執(zhí)行source /etc/profile是profile文件生效

centos6.x中如何安裝maven

7.查看是否配置成功

執(zhí)行mvn –v

centos6.x中如何安裝maven

出現(xiàn)上圖表示安裝成功。

CentOS自動安裝Maven

1. 自動下載Maven
2. 設(shè)置環(huán)境變量
3. 配置mirror
安裝:下載 maven.rar 按照 readme 執(zhí)行即可
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>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>

貼上shell 文件:

#!/bin/sh  
  
#關(guān)閉進程  
killpids(){  
  pids=($(ps -ef | grep $1 | awk '{print $2}'))  
  for pid in ${pids[@]}; do  
    echo "關(guān)閉進程: pid ${pid}"  
    kill -9 ${pid}  
  done  
}  
killpids maven  
  
#刪除舊版maven  
echo "刪除舊版maven"  
rm -rf /usr/local/apache-maven-*  
  
#install maven  
srcPath=$(find /usr/maven -maxdepth 1 -type f|grep '.*maven.*.tar.gz$')  
if [[ $srcPath =~ "maven" ]]  
  then  
    echo "安裝包:$srcPath"  
    rpm -ivh $srcPath  
  else  
    #下載maven  
    yum -y install wget  
    echo -e "Download Maven"      
    wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz -P /usr/maven/  
    srcPath=$(find /usr/maven -maxdepth 1 -type f|grep '.*maven.*.tar.gz$')  
fi  
  
#解壓  
echo "解壓..."  
tar -xf $srcPath -C /usr/local  
  
path=$(find /usr/local -maxdepth 1 -type d|grep 'apache-maven-.*')  
dir_name=${path##*/}  
echo $path  
echo $dir_name  
  
#賦予權(quán)限  
chmod -R 755 $path  
  
#設(shè)置環(huán)境變量  
sed -i '/M2_HOME/d' /etc/profile  
echo "設(shè)置環(huán)境變量"  
echo "export M2_HOME=$path" >> /etc/profile  
echo 'export PATH=$PATH:$M2_HOME/bin' >> /etc/profile  
source /etc/profile  
  
echo "建立軟鏈接 $path -> apache-maven"  
ln -s $path apache-maven  
  
echo "配置 mirrors"  
  
IFSBAK=$IFS     #備份原來的值  
IFS=#  
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>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>    
#                                                                       '  
"  
  
#循環(huán)寫入文件  
for line in $mirror;  
do  
  sed -i "/<\/mirrors>/i\ $line" $path/conf/settings.xml  
done  
IFS=$IFSBAK     #還原  
  
  
echo "mvn -v"  
mvn -v  
echo ""

感謝你能夠認真閱讀完這篇文章,希望小編分享的“centos6.x中如何安裝maven”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI