maven 安装 配置maven
maven 首先要在linux命令行就能使用maven进行构建,jenkins调用linux本地maven插件,工具,对我们项目进行构建
maven安装在linux ci-node2 服务器上
Centos 下安装 Maven
maven是java写的,所以需要安装jdk
安装 JDK
可以使用 YUM 方式安装安装 open JDK1.8 版本,也可以使用我提供的 rpm 安装,我们使用 RPM 方式安装
rpm -ivh jdk-8u121-linux-x64.rpm
[root@ci-node2 src]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
获取 Maven 安装文件
官网:http://maven.apache.org/download.cgi
清华镜像:https://mirrors.tuna.tsinghua.edu.cn/apache/maven/
[root@ci-node2 src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz --2020-04-20 00:03:35-- https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 8491533 (8.1M) [application/x-gzip] Saving to: ‘apache-maven-3.3.9-bin.tar.gz’ 100%[=================================================================>] 8,491,533 6.41MB/s in 1.3s 2020-04-20 00:03:36 (6.41 MB/s) - ‘apache-maven-3.3.9-bin.tar.gz’ saved [8491533/8491533]
安装 Maven
解压安装包
[root@ci-node2 src]# tar -xf apache-maven-3.3.9-bin.tar.gz [root@ci-node2 src]# ll total 477328 drwxr-xr-x 6 root root 99 Apr 20 00:07 apache-maven-3.3.9 -rw-r--r-- 1 root root 8491533 Nov 18 2015 apache-maven-3.3.9-bin.tar.gz drwxrwxr-x 23 root root 20480 Mar 29 23:12 git-2.9.5 -rw-r--r-- 1 root root 5928730 Dec 17 2018 git-2.9.5.tar.gz -rw-r--r-- 1 root root 167733100 Dec 17 2018 jdk-8u121-linux-x64.rpm -rw-r--r-- 1 root root 74141787 Dec 17 2018 jenkins-2.99-1.1.noarch.rpm drwxr-xr-x 2 root root 6 Apr 7 23:10 plugins -rw-r--r-- 1 root root 232436856 Dec 17 2018 plugins.tar.gz
移动包到/usr/local下
[root@ci-node2 src]# mv apache-maven-3.3.9 /usr/local/ [root@ci-node2 src]# cd /usr/local/ [root@ci-node2 local]# ll total 0 drwxr-xr-x 6 root root 99 Apr 20 00:07 apache-maven-3.3.9 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x 6 root root 58 Mar 29 23:11 git drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 49 Aug 24 2019 share drwxr-xr-x. 4 root root 187 Apr 20 00:07 src
改名
[root@ci-node2 local]# mv apache-maven-3.3.9/ maven
配置 Maven
编 辑 /etc/profile 文 件 , 在 末 尾 添 加 export PATH=/usr/local/maven/bin/:$PATH ,将 maven 命令加入系统环境变量。
就可以直接执行mvn命令
vim 保存wq 然后source /etc/profile
[root@ci-node2 local]# source /etc/profile
可以了 maven配置完成
[root@ci-node2 local]# mvn -v Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /usr/local/maven Java version: 1.8.0_121, vendor: Oracle Corporation Java home: /usr/java/jdk1.8.0_121/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"
这样maven就安装成功 ,验证maven是否安装成功
这个命令能执行成功,代表maven安装完成了
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /usr/local/maven Java version: 1.8.0_121, vendor: Oracle Corporation Java home: /usr/java/jdk1.8.0_121/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"