如何在 Windows 中更改 Maven 存储库文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4490135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change maven repository folder in windows?
提问by Victor Stafusa
In windows, maven downloads everything in the C:\Documents And Settings\MyUser\.m2
folder (or C:\Users\MyUser\.m2
). There exists some way to change the folder that it uses? Specially I want to set it to download anywhere BUT in the Documents And Settings
/Users
folder.
在 Windows 中,maven 下载C:\Documents And Settings\MyUser\.m2
文件夹(或C:\Users\MyUser\.m2
)中的所有内容。有没有办法改变它使用的文件夹?特别是我想将它设置为在Documents And Settings
/Users
文件夹中的任何位置下载。
回答by David
Look at your settings.xml
in M2_HOME/conf
(see thisfor details about setting the M2_HOME environment variable). You can add (or uncomment) the following section:
看看你settings.xml
的M2_HOME/conf
(见本关于设置M2_HOME环境变量的细节)。您可以添加(或取消注释)以下部分:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
-->
<localRepository>/path/to/local/repo</localRepository>
as suggested by the commented out section already there by default. There, you should be able to change the path to achieve what you want.
正如默认情况下已经存在的注释掉部分所建议的那样。在那里,您应该能够更改路径以实现您想要的目标。
回答by Nicomak
For Eclipse IDE
对于 Eclipse IDE
If you are using your local maven as the Maven Installation in M2 plugin in Eclispe, editing the settings.xml wasn't enough for me. The plugin was still using the default {user.home}/.m2 as the repository location.
如果您使用本地 Maven 作为 Eclispe 中 M2 插件中的 Maven 安装,编辑 settings.xml 对我来说还不够。该插件仍然使用默认的 {user.home}/.m2 作为存储库位置。
I had to go to : Windows > Preferences > Maven > User Settings
and point to my local maven's settings.xml file in the Global Settings and/or User Settings input fields. Clicking apply will then start storing artifacts in the correct destination.
我必须转到:Windows > Preferences > Maven > User Settings
并在全局设置和/或用户设置输入字段中指向我本地 Maven 的 settings.xml 文件。然后单击应用将开始在正确的目的地存储工件。