Maven的安装和配置(CentOS 7)


1. 安装

  Maven官网下载地址:http://maven.apache.org/download.cgi

  下载: wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz 

  解压: tar -zxvf apache-maven-3.6.3-bin.tar.gz 

  将解压的文件夹移动并重命名为maven:

     mv apache-maven-3.6.3 /usr/local/maven 

2.配置

  (1) 配置本地仓库

    切换到maven路径下: cd /usr/local/maven/ 

    编辑conf目录下的setting.xml文件: nano conf/settings.xml 

    配置本地仓库的目录,修改标签内容:

       /usr/local/repository 

    在标签下添加国内镜像地址:


<mirror>
<id>alimavenid>
<mirrorOf>centralmirrorOf>
<name>aliyun mavenname>
<url>http://maven.aliyun.com/nexus/content/repositories/central/url>
mirror>
<mirror>
<id>alimavenid>
<mirrorOf>centralmirrorOf>
<name>aliyun mavenname>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
mirror>

<mirror>
<id>repo1id>
<mirrorOf>centralmirrorOf>
<name>Human Readable Name for this Mirror.name>
<url>http://repo1.maven.org/maven2/url>
mirror>

<mirror>
<id>repo2id>
<mirrorOf>centralmirrorOf>
<name>Human Readable Name for this Mirror.name>
<url>http://repo2.maven.org/maven2/url>
mirror>

  (2) 配置环境变量

    切换到根目录: cd /etc 

    打开环境变量配置文件: nano profile 

    加入下面两行配置:

    export MAVEN_HOME=/usr/local/maven
    export PATH=$PATH:$MAVEN_HOME/bin

    保存并退出,刷新环境变量: source /etc/profile 

    当然也可以在 ~/.bash_profile中修改,只不过在单用户下生效。

    检查是否配置好了: mvn -version 

    

相关