Missing maven .m2 folder

WindowsMavenInstallation

Windows Problem Overview


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<username>.m2. Alas I do not have that folder. Is there some command to create this folder? Am I missing something basic?

Windows Solutions


Solution 1 - Windows

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.

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

  • Go to Start->Run
  • Type cmd and press Enter
  • At the command prompt type md c:\Users\Jonathan\.m2 (or equivalent for your ${user.home} value).

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:

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

Solution 2 - Windows

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.

Solution 3 - Windows

Use mvn -X or mvn --debug to find out from which different locations Maven reads settings.xml. This switch activates debug logging. Just check the first lines of mvn --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.

Solution 4 - Windows

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.

Solution 5 - Windows

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.

Solution 6 - Windows

> Is there some command to create this folder?

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.

Solution 7 - Windows

If I'm right, it's just because you are missing the cd command. Try c:\Users\Jonathan\cd .m2/.

Solution 8 - Windows

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,

mvn help:evaluate -Dexpression=settings.localRepository

The above command will scan for projects and run some tasks. Final outcome will be like below

enter image description here

As you can see in the picture the maven local repository is C:\Users\X\.m2\repository

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonathan LivniView Question on Stackoverflow
Solution 1 - WindowsRich SellerView Answer on Stackoverflow
Solution 2 - WindowsbharatView Answer on Stackoverflow
Solution 3 - WindowsMartin AckermannView Answer on Stackoverflow
Solution 4 - WindowsroberttdevView Answer on Stackoverflow
Solution 5 - Windowstharindu_DGView Answer on Stackoverflow
Solution 6 - WindowsGleb SView Answer on Stackoverflow
Solution 7 - WindowsVictor RossView Answer on Stackoverflow
Solution 8 - WindowsMendis CView Answer on Stackoverflow