第二节 Maven 环境配置

亮子 2021-10-25 15:38:17 17808 0 0 0

1、Maven 下载

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

图片alt

不同平台下载对应的包:

系统 包名
Windows apache-maven-3.3.9-bin.zip
Linux apache-maven-3.3.9-bin.tar.gz
Mac apache-maven-3.3.9-bin.tar.gz

2、设置 Maven 环境变量

添加环境变量 MAVEN_HOME:

  • window

图片alt

  • linux

下载解压:

# wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
# tar -xvf  apache-maven-3.3.9-bin.tar.gz
# sudo mv -f apache-maven-3.3.9 /usr/local/

编辑 /etc/profile 文件 sudo vim /etc/profile,在文件末尾添加如下代码:

export MAVEN_HOME=/usr/local/apache-maven-3.3.9
export PATH=${PATH}:${MAVEN_HOME}/bin

保存文件,并运行如下命令使环境变量生效:

# source /etc/profile

在控制台输入如下命令,如果能看到 Maven 相关版本信息,则说明 Maven 已经安装成功:

# mvn -v

3、settings.xml文件的配置

1)、配置maven本地仓库存储位置

  <localRepository>E:\repo</localRepository>

2)、远程中央仓库的镜像

  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
     <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>阿里云公共仓库snapshots</name>
      <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
  </mirrors>