Java 无法在 /var/root/.m2/repository 创建本地存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30847251/
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
Could not create local repository at /var/root/.m2/repository
提问by JohnWinter
My local maven repo is here /Users/power/.m2/repository
.
我的本地 Maven 仓库在这里/Users/power/.m2/repository
。
But I got this error
但我收到了这个错误
[java] [ERROR] Could not create local repository at /var/root/.m2/repository -> [Help 1]
Seems Maven thinks that it should use a root user repo. How can I fix it? I don't need to run my maven tasks using root permissions.
似乎 Maven 认为它应该使用 root 用户存储库。我该如何解决?我不需要使用 root 权限运行我的 Maven 任务。
回答by ingrid.e
The default maven repository is
默认的 maven 存储库是
${user.home}/.m2/repository/
but you can use settings.xml ( ${user.home}/.m2/settings.xml
) to change it to a folder that you have permissions on. Or conf/settings.xml in the ${MAVEN_HOME} and change:
但是您可以使用 settings.xml ( ${user.home}/.m2/settings.xml
) 将其更改为您拥有权限的文件夹。或 ${MAVEN_HOME} 中的 conf/settings.xml 并更改:
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Ideally, you should run maven as yourself and not root to make sure you have permissions or doing 'ksu' first and then use command line.
理想情况下,您应该以自己的身份而不是 root 身份运行 maven,以确保您拥有权限或先执行“ksu”,然后再使用命令行。
回答by Faizalsrahman
Deleting the .m2
folder manually helps sometimes
.m2
手动删除文件夹有时会有所帮助
Your .m2
folder might be corrupted and it doesn't permit you to create new or replace existing with new .m2
folder, so delete the existing .m2
folder manually by entering the below commands.
您的.m2
文件夹可能已损坏,并且不允许您创建新.m2
文件夹或用新文件夹替换现有文件夹,因此请.m2
通过输入以下命令手动删除现有文件夹。
To view the existing .m2
folder
查看现有.m2
文件夹
ls -ltra
To Delete it manually
手动删除
sudo rm .m2
回答by Adiesha
This error can occur if there is a file called .m2. (Most probably created mistakenly. This happened to me when I copied settings.xml as .m2) If you can delete this and run mvn command again it will create the .m2 folder and you can proceed without a hassel.
如果存在名为 .m2 的文件,则会发生此错误。(很可能是错误地创建。当我将 settings.xml 复制为 .m2 时,这发生在我身上)如果您可以删除它并再次运行 mvn 命令,它将创建 .m2 文件夹,您可以毫不费力地继续。