在创建Maven项目的时候,经常忘记修改本地Maven仓库的位置导致C盘空间暴涨,所以修改LocalRepository很有必要的。
Step1:
在Maven根目录下,找到conf目录,进入打开settings.xml文件。settings.xml是对Maven的基本配置,文件的基本结构如下:
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 本地仓库位置 -->
<localRepository />
<!-- 交互模式 -->
<interactiveMode />
<!-- 配置是否在build时连接网络 -->
<offline />
<!-- 插件组 -->
<pluginGroups />
<!-- -->
<servers />
<!-- 代理服务器 -->
<proxies />
<!-- 镜像位置 -->
<mirrors>
<mirror>
<id>mirrorID</id>
<mirrorOf>repositoryID</mirrorOf>
<name></name>
<url></url>
</mirror>
</mirrors>
<proxies />
<profiles />
<activeProfiles />
</settings>
默认的settings文件中都已经写好,还有许多的注释文件,此处修改LocalRepository和Mirror下的url地址即可:
原有的远程仓库镜像位置在Maven官方,服务器自然也在国外,因此修改到阿里云的公有仓库会让项目在构建过程中,下载jar包的速度更快。(图中标签都在注释当中,启用时需要消除注释)
aliyun :http://maven.aliyun.com/nexus/content/groups/public
<mirror>
<id>aliyun</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
配置好以后,在Eclipse或Intelli Idea中修改使用刚刚修改好的settings.xml文件了。
Eclipse EE中已经集成了Maven,但是需要Coder设置settings.xml,所以找到Windows -> Preference ->Maven ->Settings,如下图所示,修改settings.xml文件位置和本地仓库位置即可。
此处的Local Repository无法修改,是由于之前在settings.xml文件中已经写明了LocalRepository的位置。