ubuntu22.04 arrch64版在线安装maven

脚本

复制代码
    if type -p mvn; then
        echo "maven has been installed."
    else
        cd /home/zenglg
        wget https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz --no-check-certificate
             
        tar vxf apache-maven-3.9.5-bin.tar.gz 
        rm -rf /usr/local/maven3
        mv apache-maven-3.9.5 /usr/local/maven3
            
        #设置mvn的环境变量
        checkMvnExist()
        {
            mvn1=$(grep -n "MAVEN_HOME=.*" /etc/profile | cut -f1 -d':')
                if [ -n "$mvn1" ];then
                    sed -i "${mvn1}d" /etc/profile
                fi
            mvn2=$(grep -n "export MAVEN_HOME" /etc/profile | cut -f1 -d':')
                if [ -n "$mvn2" ];then
                    sed -i "${mvn2}d" /etc/profile
                fi
            mvn3=$(grep -n "export PATH=${PATH}:${MAVEN_HOME}/bin" /etc/profile | cut -f1 -d':')
                if [ -n "$mvn3" ];then
                    sed -i "${mvn3}d" /etc/profile
                fi
        }
        checkMvnExist

        echo "MAVEN_HOME=/usr/local/maven3" >> /etc/profile
        source /etc/profile
        echo "export MAVEN_HOME" >> /etc/profile
        if [[ ${PATH} =~ ${MAVEN_HOME}/bin ]]; then
            echo " MAVEN_HOME has been set"
        else
            echo "export PATH=${PATH}:${MAVEN_HOME}/bin" >> /etc/profile
            echo "setting MAVEN_HOME path successful."
        fi

        #保存刷新
        source /etc/profile
    fi
mvn  -v

安装成功

相关推荐
014-code14 小时前
Redisson 常用技巧
java·redis
java干货14 小时前
明明删了数据,磁盘却满了?
java
之歆14 小时前
HA 高可用集群指南
java·开发语言
CHANG_THE_WORLD15 小时前
指针入门一
java·前端·网络
时艰.15 小时前
订单系统读写分离方案设计与实现
java
014-code15 小时前
MySQL 事务隔离级别
java·数据库·mysql
hrhcode15 小时前
【Netty】三.ChannelPipeline与ChannelHandler责任链深度解析
java·后端·spring·springboot·netty
invicinble16 小时前
关于学习技术栈的思考
java·开发语言·学习
json{shen:"jing"}16 小时前
分割回文串-暴力法
java·算法
没有bug.的程序员16 小时前
Maven 进阶进阶:依赖优化内核、多模块构建艺术与“依赖地狱”自愈指南
java·maven·构建·多模块·依赖优化