如何修改eclipse中maven默认仓库路径

如题所述

从eclipse中增加了maven2的插件之后,maven默认的本地库的路径是${user}/.m2/repository/下,一般windows用户的操作系统都安装在C盘,所以这个目录下的jar包比较危险。我尝试从myeclipse->preferences->java->build path->classpath variables中查找M2_REPO这个变量,发现其路径指向的是“C:\Documents and Settings\lvxda\.m2\repository\”,我想修改其路径为:d:\m2\repository,可是这个变量的编辑按钮是灰色的,不可编辑。从网上也没有找到相应的解决办法。打算自己尝试一下:

1、手动创建本地仓库的地址为:d:/m2/repository

2、从windows的环境变量中增加了:M2_REPO=d:\m2\repository,同时把这个变量增加到path变量中。

3、修改d:\maven\conf\setting.xml文件,在<localRepository>节点下新增一行:
复制内容到剪贴板
代码:
<localRepository>d:/m2/repository</localRepository>
表示本地仓库的地址为:d:/m2/repository。
4、从myeclipse->preferences->maven->installations下add一个已经安装到d盘的maven,如:d:\maven,并勾选此新加项。并点击下面的browse按钮打开maven的全局配置文件,如:d:\maven\conf\setting.xml。

5、从myeclipse->preferences->maven->installations下修改user setting 选项为:D:\m2\repository\settings.xml,并点击update settings。并点击下面的reindex按钮更新索引。

6、点击配置窗口的apply按钮,突出配置窗口。

7、配置修改后,myeclise会自动更新索引,当完成后重启myeclipse,会发现M2_REPO变量的值变成了d:/m2/repository。

自此,maven从远程库下载的jar包都会放到d:/m2/repository下。为了避免每次构建系统都从远程仓库下载jar,需要搭建私服。
温馨提示:内容为网友见解,仅供参考
第1个回答  2018-07-05
1、本地需要安装Maven。这里假设安装在D:/Program Files/apache-maven-2.2.1
2、修改本地maven库的路径。 在D:/Program Files/apache-maven-2.2.1/conf/settings.xml 文件中修改 <localRepository>D:/Program Files/apache-maven-2.2.1/repository</localRepository> 意思是将本地仓库位置设置为D:/Program Files/apache-maven-2.2.1/repository
3、进入 MyEclipse→window→Preferences→Maven4MyEclipse→Maven→Installations→User Sittings 点击右侧Browse指向D:/Program Files/apache-maven-2.2.1/conf/settings.xml OK本回答被网友采纳
第2个回答  2017-09-24
直接去官网下载一个maven的压缩包里面有一个settings.xml文件,将里面的 <localRepository>F:\maven\m2\repository</localRepository>改掉。eclipse环境的maven默认在c盘,在eclipse中的preference中的maven setting中的两个路径改为这个setting文件,要注意将c盘中原来的文件夹全部复制到你所要的路径下
相似回答