Linux Maven

1、Maven安装包下载

A.官网地址

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

B.复制要下载的连接,在Linux使用wget下载

image.png

  1. [root@iZuligp6e1dyzfZ maven]# wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
  2. --2020-07-27 09:31:58-- https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
  3. Resolving mirrors.bfsu.edu.cn (mirrors.bfsu.edu.cn)... 39.155.141.16, 2001:da8:20f:4435:4adf:37ff:fe55:2840
  4. Connecting to mirrors.bfsu.edu.cn (mirrors.bfsu.edu.cn)|39.155.141.16|:443... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 9506321 (9.1M) [application/octet-stream]
  7. Saving to: apache-maven-3.6.3-bin.tar.gz
  8. 100%[==============================================================================>] 9,506,321 18.3MB/s in 0.5s
  9. 2020-07-27 09:31:59 (18.3 MB/s) - apache-maven-3.6.3-bin.tar.gz saved [9506321/9506321]
  10. [root@iZuligp6e1dyzfZ maven]# ll
  11. total 9284
  12. -rw-r--r-- 1 root root 9506321 Nov 20 2019 apache-maven-3.6.3-bin.tar.gz

2、解压安装包

  1. [root@iZuligp6e1dyzfZ maven]# tar -zxvf apache-maven-3.6.3-bin.tar.gz

3、配置Maven的conf目录下的setting.xml文件

A.创建本地仓库目录(尽量放置在Maven解压包同目录下,便于后期Maven升级时直接引用)

  1. [root@iZuligp6e1dyzfZ maven]# mkdir Repo
  2. [root@iZuligp6e1dyzfZ maven]# cd Repo/
  3. [root@iZuligp6e1dyzfZ Repo]# pwd
  4. /local/maven/Repo

B.将本地仓库目录配置至Maven解压目录下的conf目录里的settings.xml文件中

  1. [root@iZuligp6e1dyzfZ apache-maven-3.6.3]# cd conf/
  2. [root@iZuligp6e1dyzfZ conf]# vim settings.xml

添加如下内容

  1. <localRepository>/local/maven/Repo</localRepository>

image.png

C.配置私服仓库地址

image.png
找到mirrors节点,添加如下内容

  1. <!-- 阿里云仓库 -->
  2. <mirror>
  3. <id>alimaven</id>
  4. <mirrorOf>central</mirrorOf>
  5. <name>aliyun maven</name>
  6. <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
  7. </mirror>
  8. <mirror>
  9. <id>alimaven</id>
  10. <name>aliyun maven</name>
  11. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  12. <mirrorOf>central</mirrorOf>
  13. </mirror>
  14. <!-- 中央仓库 -->
  15. <mirror>
  16. <id>repo</id>
  17. <mirrorOf>central</mirrorOf>
  18. <name>Human Readable Name for this Mirror.</name>
  19. <url>http://repo1.maven.org/maven2/</url>
  20. </mirror>
  21. <mirror>
  22. <!-- 官方源1-->
  23. <id>central</id>
  24. <name>Maven Repository Switchboard</name>
  25. <url>http://repo1.maven.org/maven2/</url>
  26. <mirrorOf>central</mirrorOf>
  27. </mirror>
  28. <mirror>
  29. <!-- 官方源2-->
  30. <id>repo2</id>
  31. <mirrorOf>central</mirrorOf>
  32. <name>Human Readable Name for this Mirror.</name>
  33. <url>http://repo2.maven.org/maven2/</url>
  34. </mirror>
  35. <mirror>
  36. <!-- ibiblio镜像源-->
  37. <id>ibiblio</id>
  38. <mirrorOf>central</mirrorOf>
  39. <name>Human Readable Name for this Mirror.</name>
  40. <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
  41. </mirror>
  42. <mirror>
  43. <!-- jboss镜像源-->
  44. <id>jboss-public-repository-group</id>
  45. <mirrorOf>central</mirrorOf>
  46. <name>JBoss Public Repository Group</name>
  47. <url>http://repository.jboss.org/nexus/content/groups/public</url>
  48. </mirror>
  49. <!-- 中央仓库在中国的镜像 -->
  50. <mirror>
  51. <id>maven.net.cn</id>
  52. <name>oneof the central mirrors in china</name>
  53. <url>http://maven.net.cn/content/groups/public/</url>
  54. <mirrorOf>central</mirrorOf>
  55. </mirror>

4、将Maven的解压目录配置至系统环境变量

  1. [root@iZuligp6e1dyzfZ apache-maven-3.6.3]# pwd
  2. /local/maven/apache-maven-3.6.3
  3. [root@iZuligp6e1dyzfZ apache-maven-3.6.3]# vim /etc/profile

添加如下配置

  1. # Maven环境变量配置
  2. export MAVEN_HOME=/local/maven/apache-maven-3.6.3
  3. export PATH=$MAVEN_HOME/bin:$PATH

image.png

5、刷新配置使其生效

  1. [root@iZuligp6e1dyzfZ apache-maven-3.6.3]# source /etc/profile

6、使用 mvn -v 命令检查安装完成

  1. [root@iZuligp6e1dyzfZ apache-maven-3.6.3]# mvn -v
  2. Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
  3. Maven home: /local/maven/apache-maven-3.6.3
  4. Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: /local/jdk/jdk1.8.0_161/jre
  5. Default locale: en_US, platform encoding: UTF-8
  6. OS name: "linux", version: "3.10.0-514.26.2.el7.x86_64", arch: "amd64", family: "unix"

image.png