windows 缺少 maven .m2 文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6081617/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:24:01  来源:igfitidea点击:

Missing maven .m2 folder

windowsmaveninstallation

提问by Jonathan

AFAIK maven does not have an installer for Windows, you simply unzip it wherever you like, as explained here.

AFAIK行家没有为Windows安装程序,你只需将它解压缩你喜欢的地方,如解释在这里

However in many places there are references to a .m2folder 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?

但是,在很多地方都引用.m2了用户文件夹下的文件夹(在 Win7 中,我猜它默认为C:\Users\.m2。唉,我没有那个文件夹。有没有一些命令来创建这个文件夹?我错过了一些基本的东西吗?

回答by Rich Seller

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 under c:\Users\Jonathan\.m2.

在 Windows 机器上,.m2 文件夹应该位于${user.home}. 在 Windows 7 和 Vista 上,这可以解析为 ,<root>\Users\<username>而在 XP 上则为<root>\Documents and Settings\<username>\.m2。所以你通常会在c:\Users\Jonathan\.m2.

If you want to create a folder with a .prefix on Windows, you can simply do this on the command line.

如果要.在 Windows 上创建带有前缀的文件夹,只需在命令行上执行此操作即可。

  • Go to Start->Run
  • Type cmdand press Enter
  • At the command prompt type md c:\Users\Jonathan\.m2(or equivalent for your ${user.home} value).
  • 转到开始->运行
  • 键入CMD,然后按Enter键
  • 在命令提示符下键入md c:\Users\Jonathan\.m2(或与 ${user.home} 值等效的值)。

Note that you don't actually need the .m2location unless you want to create a distinct user settings file, which is optional (see the Settings referencefor more details).

请注意,您实际上并不需要.m2位置,除非您想创建一个不同的用户设置文件,这是可选的(有关更多详细信息,请参阅设置参考)。

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).

如果您不需要单独的用户设置文件并且真的不希望您的用户主目录下的本地存储库,您可以通过修改全局设置文件(位于 \conf\settings .xml)。

The following snippet would set the local repository to c:\Maven\repositoryfor example:

以下代码段将本地存储库设置c:\Maven\repository为例如:

<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
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>c:\Maven\repository</localRepository>
  ...

回答by bharat

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.

首次安装 maven 时,.m2 文件夹不会出现在 C:\Users\ {user} 路径中。要生成文件夹,您必须运行任何 maven 命令,例如 mvn clean、mvn install 等,以便它在 .m2 文件夹中搜索 settings.xml,并在未找到时创建一个。

So long story cur short, open cmd -> mvn install

长话短说,打开 cmd -> mvn install

It will show could not find any projects(Don't worry maven is working fine :P) now check your user folder.

它将显示找不到任何项目(不要担心 maven 工作正常:P)现在检查您的用户文件夹。

P.S. If still not able to view .m2 folder try unhiding hidden items.

PS 如果仍然无法查看 .m2 文件夹,请尝试取消隐藏隐藏项目。

回答by Martin Ackermann

Use mvn -Xor mvn --debugto find out from which different locations Maven reads settings.xml. This switchactivates debug logging. Just check the first lines of mvn --debug | findstr /i /c:using /c:reading.

使用mvn -Xmvn --debug找出 Maven 从哪些不同位置读取 settings.xml。此开关激活调试日志记录。只需检查mvn --debug | findstr /i /c:using /c:reading.



Right, Maven uses the Java system property user.homeas location for the .m2 folder.

没错,Maven 使用 Java 系统属性user.home作为 .m2 文件夹的位置。

But user.homedoes not alwaysresolve to %USERPROFILE%\.m2. If you have moved the location of your Desktop folder to another place, user.homemight 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.

user.home并不总是下定决心%USERPROFILE%\.m2。如果您已将桌面文件夹的位置移动到其他位置,则user.home可能会解析到此新桌面文件夹的父目录。当将 Windows Vista 或更新的 Windows 与 Java 7 或任何较旧的 Java 版本一起使用时,会发生这种情况。

The blog post Java's “user.home” is Wrong on Windowsdescribes 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.

博客文章Java 的“user.home”在 Windows 上是错误的,对此进行了很好的描述,并提供了指向官方错误报告的链接。该错误在 Java 8 中被标记为已解决。博客访问者 Lars 的评论提出了一个很好的解决方法。

回答by roberttdev

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.

您是否将文件系统显示配置设置为显示隐藏文件和文件夹?如果我没记错的话,默认情况下它是隐藏的。应该在 c:\users\username\.m2 下。

回答by tharindu_DG

Check the configurations in {M2_HOME}\conf\setting.xml as mentioned in the following link.

检查 {M2_HOME}\conf\setting.xml 中的配置,如以下链接中所述。

http://www.mkyong.com/maven/where-is-maven-local-repository/

http://www.mkyong.com/maven/where-is-maven-local-repository/

Hope this helps.

希望这可以帮助。

回答by Gleb S

Is there some command to create this folder?

是否有一些命令可以创建此文件夹?

If smb face this issue again, you should know the most simple way to create .m2folder.
If you unzipped maven and set up maven path variable - just try mvn cleancommand from anywhere you like!
Dont be afraid of error messages when running - it works and creates needed directory.

如果 smb 再次遇到此问题,您应该知道创建.m2文件夹的最简单方法。
如果您解压缩了 Maven 并设置了 Maven 路径变量 - 只需mvn clean从您喜欢的任何地方尝试命令!
运行时不要害怕错误消息 - 它可以工作并创建所需的目录。