缺少 Maven .m2 文件夹
AFAIK maven 没有适用于 Windows 的安装程序,您只需将其解压缩到您喜欢的任何位置,如此处所述。
然而,在许多地方都引用了用户文件夹下的 .m2
文件夹(在 Win7 中,我猜它默认位于 C:\Users\.m2
)。唉,我没有这个文件夹,有什么命令可以创建这个文件夹吗?
AFAIK maven does not have an installer for Windows, you simply unzip it wherever you like, as explained here.
However in many places there are references to a .m2
folder under the user folder (in Win7 I would guess it to be by default at C:\Users\.m2
. Alas I do not have that folder. Is there some command to create this folder? Am I missing something basic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在 Windows 计算机上,.m2 文件夹应位于
${user.home}
下。在 Windows 7 和 Vista 上,此解析为\Users\
,在 XP 上则解析为\Documents and Settings\\.m2
。因此,您通常会在c:\Users\Jonathan\.m2
下看到它。如果您想在 Windows 上创建带有
.
前缀的文件夹,只需在命令行上执行此操作即可。请注意,您实际上并不需要 .m2 位置,除非您想创建一个不同的用户设置文件,该文件是可选的(请参阅 设置参考了解更多详细信息)。
如果您不需要单独的用户设置文件,并且并不真正需要用户主目录下的本地存储库,您可以通过修改全局设置文件(位于 \conf\settings 中)将存储库的位置简单地设置为不同的文件夹.xml)。
例如,以下代码片段将本地存储库设置为
c:\Maven\repository
:On a Windows machine, the .m2 folder is expected to be located under
${user.home}
. On Windows 7 and Vista this resolves to<root>\Users\<username>
and on XP it is<root>\Documents and Settings\<username>\.m2
. So you'd normally see it underc:\Users\Jonathan\.m2
.If you want to create a folder with a
.
prefix on Windows, you can simply do this on the command line.Note that you don't actually need the .m2 location unless you want to create a distinct user settings file, which is optional (see the Settings reference for more details).
If you don't need a separate user settings file and don't really want the local repository under your user home you can simply set the location of your repository to a different folder by modifying the global settings file (located in \conf\settings.xml).
The following snippet would set the local repository to
c:\Maven\repository
for example:首次安装 maven 时,.m2 文件夹不会出现在 C:\Users\ {user} 路径中。
要生成该文件夹,您必须运行任何 Maven 命令,例如 mvn clean、mvn install 等,以便它在 .m2 文件夹中搜索 settings.xml,如果找不到,则创建一个。
故事长话短说,
打开cmd-> mvn install
会显示找不到任何项目(不用担心maven工作正常:P)
现在检查您的用户文件夹。
PS 如果仍然无法查看 .m2 文件夹,请尝试取消隐藏隐藏项目。
When you first install maven, .m2 folder will not be present in C:\Users\ {user} path.
To generate the folder you have to run any maven command e.g. mvn clean, mvn install etc. so that it searches for settings.xml in .m2 folder and when not found creates one.
So long story cur short,
open cmd -> mvn install
It will show could not find any projects(Don't worry maven is working fine :P)
now check your user folder.
P.S. If still not able to view .m2 folder try unhiding hidden items.
使用
mvn -X
或mvn --debug
找出 Maven 从哪些不同位置读取 settings.xml。 此开关激活调试日志记录。只需检查 mvn --debug | 的第一行findstr /i /c:using /c:reading。是的,Maven 使用 Java 系统属性
user.home
作为 .m2 文件夹的位置。但
user.home
并不总是解析为%USERPROFILE%\.m2
。如果您已将“桌面”文件夹的位置移动到其他位置,user.home
可能会解析为这个新“桌面”文件夹的父目录。当将 Windows Vista 或更新的 Windows 与 Java 7 或任何较旧的 Java 版本一起使用时,会发生这种情况。博客文章 Java 的“user.home”在 Windows 上是错误的< /a> 对其进行了很好的描述,并提供了官方错误报告的链接。该错误在 Java 8 中被标记为已解决。博客访问者 Lars 的评论提出了一个很好的解决方法。
Use
mvn -X
ormvn --debug
to find out from which different locations Maven reads settings.xml. This switch activates debug logging. Just check the first lines ofmvn --debug | findstr /i /c:using /c:reading
.Right, Maven uses the Java system property
user.home
as location for the .m2 folder.But
user.home
does not always resolve to%USERPROFILE%\.m2
. If you have moved the location of your Desktop folder to another place,user.home
might resolve to the parent directory of this new Desktop folder. This happens when using Windows Vista or a more recent Windows together with Java 7 or any older Java version.The blog post Java’s “user.home” is Wrong on Windows describes it very well and gives links to the official bug reports. The bug is marked as resolved in Java 8. The comment of the blog's visitor Lars proposes a nice workaround.
如果找不到默认的.m2,可能有人更改了默认路径。发出以下命令来查找 Maven 本地存储库在哪里,
上面的命令将扫描项目并运行一些任务。
最终结果如下
正如您在图片中看到的,maven 本地存储库是 C:\Users\X\.m2\repository
If the default .m2 is unable to find, maybe someone changed the default path. Issue the following command to find out where is the Maven local repository,
The above command will scan for projects and run some tasks.
Final outcome will be like below
As you can see in the picture the maven local repository is C:\Users\X\.m2\repository
您是否已将文件系统显示配置设置为显示隐藏的文件和文件夹?如果我没记错的话,默认情况下它是隐藏的。应位于 c:\users\username\.m2 下。
Do you have the file system display config set up to show hidden files and folders? If I remember correctly, by default it's hidden. Should be under c:\users\username\.m2.
检查 {M2_HOME}\conf\setting.xml 中的配置,如以下链接所述。
http://www.mkyong.com/maven/where-is- maven-local-repository/
希望这有帮助。
Check the configurations in {M2_HOME}\conf\setting.xml as mentioned in the following link.
http://www.mkyong.com/maven/where-is-maven-local-repository/
Hope this helps.
如果中小企业再次遇到这个问题,您应该知道创建
.m2
文件夹的最简单方法。如果您解压了 maven 并设置了 maven 路径变量 - 只需从您喜欢的任何地方尝试
mvn clean
命令即可!运行时不要害怕错误消息 - 它可以工作并创建所需的目录。
If smb face this issue again, you should know the most simple way to create
.m2
folder.If you unzipped maven and set up maven path variable - just try
mvn clean
command from anywhere you like!Dont be afraid of error messages when running - it works and creates needed directory.
如果我是对的,那只是因为您缺少 cd 命令。尝试
c:\Users\Jonathan\cd .m2/
。If I'm right, it's just because you are missing the
cd
command. Tryc:\Users\Jonathan\cd .m2/
.您的系统中需要有 Maven。
请在环境变量中添加 Maven Home 或 M2 Home [M2_HOME/ MAVEN_HOME]
3)在环境变量中添加您的maven路径。
4)现在打开cmd并运行mvn;它将创建该文件夹。
You need to have Maven in your system.
Please add Maven Home or M2 Home in your Environment Variables[M2_HOME/ MAVEN_HOME]
3)Add the path of your maven in Environment Variables.
4)now open cmd and run mvn ; it will create the folder.