86

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?

Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
  • 1
    I would expect it to be under wherever the `java.home` Java [system property](http://download.oracle.com/javase/6/docs/api/java/lang/System.html#getProperties%28%29) points to (by default). It will be created by Maven if it does not exist. – McDowell May 21 '11 at 12:15

8 Answers8

107

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>
  ...
Rich Seller
  • 83,208
  • 23
  • 172
  • 177
  • 1
    Very clear answer! tried it and it solved my problem. But you answered a different question I asked on SA. Rich, if you'll copy paste the last part of your answer to my other question, I'll give you the credit of the correct answer. The Q is here: http://stackoverflow.com/questions/6081838/how-to-set-where-maven-installs-plugins – Jonathan Livni May 21 '11 at 22:06
  • Glad it helped, I've modified the answer slightly to better fit the other question. – Rich Seller May 21 '11 at 22:41
  • 1
    Rich, I'm giving you the answer because you helped me solve my problem, although you didn't help me understand why I (still) don't have the .m2 directory... – Jonathan Livni May 22 '11 at 12:07
  • 1
    If you want to create it from Windows Explorer, you need to create a folder with the name `.m2.`(note the trailing dot). Don't worry, windows will remove the trailing dot for you. – Stef Dec 23 '14 at 01:27
42

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.

bharat
  • 429
  • 4
  • 3
18

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.

robert4
  • 1,072
  • 15
  • 20
Martin Ackermann
  • 1,066
  • 10
  • 15
  • This answer lead me to solve my problem. In my case the maven command was run under SYSTEM account by some script. On previous server, the `.m2` was located at `C:\.m2`. But on a recent server update (with newer windows) it seems to be found on `C:\Windows\System32\config\systemprofile\.m2` – Julio Aug 04 '20 at 12:31
2

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.

roberttdev
  • 42,762
  • 2
  • 20
  • 23
  • yes I do :) What should create this folder in the first place? – Jonathan Livni May 21 '11 at 12:37
  • 1
    I believe it's created when you run your first project through maven. Has your project built successfully, and if not how far did it make it? – roberttdev May 21 '11 at 12:39
  • no it did not due to this currently unsolved question: http://stackoverflow.com/questions/6081275/maven-wont-download-a-plugin?answertab=oldest#tab-top – Jonathan Livni May 21 '11 at 12:44
  • Ah, that makes sense. Once you get that jar visible to Maven and start the build successfully, the directory should show up. – roberttdev May 21 '11 at 13:58
  • If I require a successful build start to have the .m2 directory, and only through this directory I might be able to resolve the following issue, then I'm at a deadlock - http://stackoverflow.com/questions/6081838/how-to-set-where-maven-installs-plugins – Jonathan Livni May 21 '11 at 16:37
  • There is also a global settings.xml file in the conf directory of your Maven distribution to set your wanted settings (and this would be the right point for settings that apply to all users). – dunni May 21 '11 at 19:40
  • Following Rich Seller's answer, I was able to successfully build. Alas the .m2 directory is still missing from C:\Users\Jonathan... a mystery... – Jonathan Livni May 21 '11 at 22:07
2

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

0

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.

tharindu_DG
  • 8,900
  • 6
  • 52
  • 64
0

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.

Gleb S
  • 403
  • 1
  • 5
  • 13
0

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

double-beep
  • 5,031
  • 17
  • 33
  • 41