#---------------------------------------------------
#maven3自动安装脚本
#---------------------------------------------------
#---------------------------------------------------
#1、下载安装mava3
echo '(1/5)、开始下载安装maven3'
mkdir /usr/local/maven
mkdir /usr/local/maven/repository
cd /usr/local/maven
wget https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz
#---------------------------------------------------
#2、解压mava3
echo '(2/5)、开始解压maven3'
tar -zxvf apache-maven-3.8.4-bin.tar.gz
#---------------------------------------------------
#3、设置MAVEN_HOME
echo '(3/5)、开始设置MAVEN_HOME'
echo -e "\n#maven3" >> /etc/profile
echo "MAVEN_HOME=/usr/local/maven/apache-maven-3.8.4" >> /etc/profile
echo "export PATH=\${MAVEN_HOME}/bin:\${PATH}" >> /etc/profile
source /etc/profile
#---------------------------------------------------
#4、配置阿里镜像
echo '(4/5)、开始配置阿里镜像'
mirror="\n<mirror>\n<id>alimaven</id>\n<name>aliyun maven</name>\n<url>http://maven.aliyun.com/nexus/content/groups/public/</url>\n<mirrorOf>central</mirrorOf>\n</mirror>"
sed -i "/<\/mirrors>/ i\ ${mirror}" /usr/local/maven/apache-maven-3.8.4/conf/settings.xml
#---------------------------------------------------
#5、指定资源下载存放位置与指定jdk
echo '(5/5)、开始指定资源下载存放位置与指定jdk'
localRepository="\n<localRepository>/usr/local/maven/repository</localRepository>"
sed -i "/<\/settings>/ i\ ${localRepository}" /usr/local/maven/apache-maven-3.8.4/conf/settings.xml
jdk="\n<profile>\n<id>jdk-1.8</id>\n<activation>\n<activeByDefault>true</activeByDefault>\n<jdk>1.8</jdk>\n</activation>\n<properties>\n<maven.compiler.source>1.8</maven.compiler.source>\n<maven.compiler.target>1.8</maven.compiler.target>\n<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>\n</properties>\n</profile>"
sed -i "/<\/profiles>/ i\ ${jdk}" /usr/local/maven/apache-maven-3.8.4/conf/settings.xml
echo 'maven3自动安装完成'
最后执行mvn –version查看