0. Maven下载
下载地址:https://maven.apache.org/download.cgi
image.png
Binary:编译之后的二进制文件
Source:表示可以查看源代码的,比Binary大一点
tar.gz archive:Linux、macOS系统使用
zip archive:Windows系统使用
1. settings.xml配置
Step 1. 解压,找到conf目录下的settings.xml配置文件,默认的镜像下载速度很慢,我们可以换成阿里云的镜像。
    <mirror>      
      <id>alimaven</id>    
      <name>aliyun maven</name>      
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>      
      <mirrorOf>central</mirrorOf>  
    </mirror> 
image.png
Step 2. 更改仓库的位置,仓库就是我们通过Maven下载的jar包存放的地方
<localRepository>/path/to/local/repo</localRepository>
image.png
2. 配置环境变量
Step 1. 打开终端,vi ~/.bash_profile
Step 2. 添加Maven环境变量
export MAVEN_HOME=/Users/aaron/Mine/Coder/LocalRepository
export PATH=$PATH:$MAVEN_HOME/bin
Step 3. 保存并source ~/.bash_profile,使配置生效
Step 4. mvn -v,出现如下结果表明配置成功
image.png
3. IntelliJ IDEA Maven配置
Step 1. 打开IntelliJ IDEA->Configure->Preference->Build->Build Tools->Maven
image.png
Step 2. 主要配置下图红框内三个内容
image.png
4. (拓展)CentOS 7安装Maven
Step 1. 将apache-maven-3.6.3-bin.tar.gz上传至/export/softwares
Step 2. 解压tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /export/servers/
Step 3.
- 编辑配置文件
vi /export/servers/apache-maven-3.6.3/conf/settings.xml,换成阿里云的镜像 
    <mirror>      
      <id>alimaven</id>    
      <name>aliyun maven</name>      
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>      
      <mirrorOf>central</mirrorOf>  
    </mirror>  
image.png
- 修改仓库的位置
 
<localRepository>/path/to/local/repo</localRepository>
image.png
Step 4. 添加环境变量vi /etc/profile,保存并source /etc/profile使之生效
export M2_HOME=/export/servers/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin
Step 5. mvn -v查看环境变量是否添加成功
image.png













网友评论