maven下载
官网下载maven安装包
http://maven.apache.org/download.cgi

sudo wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz
sudo wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.zip
sudo wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.0/source/apache-maven-3.6.0-src.tar.gz

maven安装
依赖为jdk1.7以上
解压包
sudo tar -zxvf apache-maven-3.6.0-bin.tar.gz -C /data/Maven

配置环境变量
vi /etc/profile 或者 vi ~/bash_profile
##maven###
export MAVEN_HOME=/data/Maven/apache-maven-3.6.0
export MAVEN_OPTS="-Xms128m -Xmx1024m"
export PATH=$MAVEN_HOME/bin:$PATH

source /etc/profile 或者 source ~/bash_profile
测试
mvn -v
有如下信息说明安装成功
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: /data/Maven/apache-maven-3.6.0
Java version: 1.8.0_131, vendor: Oracle Corporation, runtime: /usr/local/java/jdk1.8.0_131/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.26.2.el7.x86_64", arch: "amd64", family: "unix"

maven使用与技巧
1、Pom文件介绍与基本组成

  说明:全称是Project Object Model,通俗点的话说就是要对构建的项目进模

2、maven repository 与镜像地址 

http://mvnrepository.com maven 仓库用于查找所需要pom项目

http://repo1.maven.org/maven2/ 全球总仓库1

http://repo2.maven.org/maven2/ 全球总仓库2

http://central.maven.org/maven2/ 全球总仓库3

http://maven.aliyun.com/nexus/content/groups/public/ 阿里云镜像仓库
http://maven.aliyun.com/nexus/content/repositories/central/ 阿里云镜像仓库

镜像配置:

修改settings.xml 文件

1
2   
3     alimaven
4     aliyun maven
5     http://maven.aliyun.com/nexus/content/groups/public/;
6     central
7   

8   
9   
10     repo1
11     central
12     Human Readable Name for this Mirror.
13     http://repo1.maven.org/maven2/;
14   

15
16   
17   
18     repo2
19     central
20     Human Readable Name for this Mirror.
21     http://repo2.maven.org/maven2/;
22   

23

本地仓配置
vi /data/Maven/apache-maven-3.6.0/conf/settings.xml
/data/Maven/m2/repository

在终端运行命令将常用的包从maven中央仓库下载文件到本地:
mvn help:system
没有错误的话,打开 /usr/local/maven_repository 会发现多了很多文件

mvn常用

1 mvn clean //清空class文件
2 mvn coplile //编译
3 mvn package //打包
4 mvn test //测试
5 mvn install //打包并上传至本地仓库
6 mvn deploy //上传到远程仓库
7 mvn -Dmaven.test.skip=true //跳过测试