下载
-
maven官网地址
-
配置环境变量
-
在配置之前请将JDK安装好。
-
添加M2_HOME:对应Maven的解压目录即可。
- 编辑Path环境变量:
-
添加 %M2_HOME%\bin
-
测试,在cmd窗口输入
mvn -v
查看 -
显示如下即配置成功
-
为什么慢
执行 mvn 各种命令的时候,默认是去 maven 官方镜像源获取需要安装的具体软件信息
默认源地址在国外,从国内访问的速度肯定比较慢
方法一: 配置只在当前项目生效
-
在 pom.xml 文件内添加以下配置
ali-maven http://maven.aliyun.com/nexus/content/groups/public
方法二: 配置全局生效
-
修改 settings.xml 文件
- 找到 mirrors 标签,在里面加入以下内容
alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central -
可以在以下路径查找到 settings.xml 文件
-
(用户家目录)/.m2/settings.xml
-
(maven 安装目录)/conf/settings.xml,
如果是 Mac 系统通过 brew 命令安装的,在这里:
/usr/local/Cellar/maven/(版本号)/libexec/conf/settings.xml
-
参考地址
详细配置
<?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/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>central repo</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>apache snapshots</mirrorOf>
<name>阿里云阿帕奇仓库</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</mirror>
</mirrors>
<proxies/>
<activeProfiles/>
<profiles>
<profile>
<repositories>
<repository>
<id>aliyunmaven</id>
<name>aliyunmaven</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>MavenCentral</id>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>aliyunmavenApache</id>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
文章评论