1、下载
官网:http://maven.apache.org/download.cgi
2、解压
tar zxvf apache-maven-3.6.1-bin.tar.gz -C /opt/
解压之后的目录为 : /opt/apache-maven-3.6.1/
3、环境变量
vim /etc/profile
在打开的文件最后面添加以下信息
export M2_HOME=/opt/apache-maven-3.6.1
export PATH=$PATH:$M2_HOME/bin
让配置生效
source /etc/profile
验证是否安装完成
mvn -version
至此,安装成功!
4、配置文件详解
<?xml version="1.0" encoding="UTF-8"?>
<settings
xmlns="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>C:Usersasus.m2
epository</localRepository>
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host>proxy.host.net</host><port>80</port><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy>
-->
</proxies>
<!-- 仓库服务配置 -->
<servers>
<!-- 私服的验证信息 -->
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<!-- 镜像配置 -->
<mirrors>
<!-- 下面是我们搭的私服仓库。maven对全部仓库的访问全部拦截到私服的public仓库中去,如果私服关闭,那么就不能访问中央工厂了 -->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.xbdream.cn:8000/content/groups/public/</url>
</mirror>
<!-- 下面是阿里云私服仓库 -->
<!-- <mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror> -->
</mirrors>
<!-- 一些自定义配置 -->
<profiles>
<profile>
<id>myProfile</id>
<!-- 激活这个配置 -->
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<!-- 全局属性配置,让所有 maven 项目新建时默认都是 java8、UTF-8 -->
<properties>
<jdk.version>1.8</jdk.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
</properties>
<!--依赖仓库的一些配置,其主要作用是用来覆写 nexus 仓库的一些策略-->
<repositories>
<repository>
<id>nexus</id>
<name>Nexus</name>
<url>http://nexus.xbdream.cn:8000/content/groups/public/</url>
<!-- 允许下载 releases 类型依赖 -->
<releases><enabled>true</enabled></releases>
<!-- 允许下载 snapshots 类型依赖 -->
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<!--插件仓库配置-->
<pluginRepositories>
<pluginRepository>
<id>nexusPluginRepositories</id>
<url>http://nexus.xbdream.cn:8000/content/groups/public/</url>
<!-- 允许下载 releases 类型依赖 -->
<releases><enabled>true</enabled></releases>
<!-- 允许下载 snapshots 类型依赖 -->
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>