Maven安装
1、Linux下Maven安装
1.1 下载安装包
maven 官网地址:https://maven.apache.org/download.cgi
安装包下载地址:https://dlcdn.apache.org/maven/maven-3
这里下载 apache-maven-3.3.9-bin.tar.gz
下载后上传到Linux服务器
1.2 安装Maven
解压 maven 安装包到 maven 文件夹:
$ mkdir -p /home/zhangshixing/maven
$ tar -zxvf apache-maven-3.3.9-bin.tar.gz -C /home/zhangshixing/maven
创建 maven 资源库目录:
$ mkdir -p /home/zhangshixing/maven/m2/repository
编辑 settings.xml 文件:
$ cd /home/zhangshixing/maven/apache-maven-3.3.9/conf/
$ vim settings.xml
将原文件内容全部删除,添加新的配置内容,删除命令:
:1,.d
新的配置内容,修改了资源库位置,添加了阿里云国内镜像:
<?xml version="1.0" encoding="UTF-8"?>
<settingsxmlns="http://maven.apache.org/SETTINGS/1.2.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"><localRepository>/home/zhangshixing/maven/m2/repository</localRepository><pluginGroups></pluginGroups><proxies></proxies><servers></servers><mirrors><mirror><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror></mirrors><profiles></profiles>
</settings>
1.3 添加环境变量
vim /etc/profile
添加 maven 环境变量内容
MAVEN_HOME=/home/zhangshixing/maven/apache-maven-3.3.9
PATH=$MAVEN_HOME/bin:$PATH
export MAVEN_HOME PATH
重新加载配置文件
source /etc/profile
1.4 测试
$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /home/zhangshixing/maven/apache-maven-3.3.9
Java version: 11.0.17, vendor: Red Hat, Inc.
Java home: /usr/lib/jvm/java-11-openjdk-11.0.17.0.8-2.el7_9.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.80.1.el7.x86_64", arch: "amd64", family: "unix"
2、Windows下Maven安装
安装包下载地址:https://dlcdn.apache.org/maven/maven-3
这里下载 apache-maven-3.3.9-bin.zip
2.1 解压安装包
下载安装包之后将安装包解压到 D:\DecompressionSoftwareInstall
目录。
解压之后的目录:D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin
2.2 新建本地仓库
新建仓库目录:D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin\repository
2.3 修改配置文件配置远程仓库和本地仓库
修改 D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin\conf\settings.xml
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<settingsxmlns="http://maven.apache.org/SETTINGS/1.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><localRepository>D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin\repository</localRepository><pluginGroups></pluginGroups><proxies></proxies><servers></servers><mirrors><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/repositories/central/</url></mirror></mirrors><profiles><profile><id>jdk-1.8</id><activation><activeByDefault>true</activeByDefault><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties></profile></profiles>
</settings>
2.4 配置环境变量
配置环境变量:
M2_HOME = D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin
2.5 查看版本
$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: D:\DecompressionSoftwareInstall\apache-maven-3.3.9-bin
Java version: 1.8.0_77, vendor: Oracle Corporation
Java home: D:\OwnerSoftwareInstall\jdk\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"