Where is Maven local repository?

The maven local repository is a local folder that is used to store all your project’s dependencies (plugin jars and other files which are downloaded by Maven). In simple, when you build a Maven project, all dependency files will be stored in your Maven local repository.

By default, Maven local repository is default to .m2 folder :

  1. Unix/Mac OS X – ~/.m2
  2. Windows – C:\Documents and Settings\{your-username}\.m2

1. Update Maven Local Repository

Normally, I will change the default local repository folder from default .m2 to another more meaningful name, for example, maven-repo.

Find {M2_HOME}\conf\setting.xml, update localRepository to something else.

{M2_HOME}\conf\setting.xml

<settings>
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

<localRepository>D:/maven_repo</localRepository>

2. Saved it

Done, your new Maven local repository is now changed to D:/maven_repo.

See figure :

Maven local repository

References

  1. Introduction to Repositories

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
trackback
Where is maven central repository ?

[…] this case, If Maven can’t find your dependency libraries in your Maven local repository, it will try download it from the default Maven central repository, which is […]

Jason Robinson
Guest
Jason Robinson

I have been looking for a multiple local repository fall back solution. In otherwords, if the group intranet server (hosting the maven repo) isn’t available, then check the local (C:/) repo and if you can’t find something there, go to maven central.

martin
Guest
martin

Hi,

All your tutorials are very well explained, in detail and in step by step way.
You are doing a wonderful job!

Ash Trick
Guest
Ash Trick

quick question, there is a repository.xml in the local repository. What is that used for?

Nanuk
Guest
Nanuk

As I understand jars are downloaded by Maven automatically , when we adding dependency in pom . But from where maven download jars ?

Ali
Guest
Ali

Short , Simple and Best description…!Thanks

Amol Manthalkar
Guest
Amol Manthalkar

Hi,

It would be easy to proceed through the tutorial if we can have next and previous button at the end of topic. :)

Amal
Guest
Amal

Hi i’m using netbeans 7.3 and i can’t find maven repository browser in (window->other ).

Jason Robinson
Guest
Jason Robinson

I’m using netbeans as well. Don’t use Netbeans to try to browse a repository. Maven is meant to run OUTSIDE of an IDE.

Al Mobe
Guest
Al Mobe

You just missed about the eclipse update for this solution. I found a best practice to change maven local repository here
http://jroadie.com/maven/how-to-change-maven-local-repository/

elzakaria
Guest
elzakaria

Thanks a lot, just curious, when you said

Find {M2_HOME}\conf\setting.xml, update localRepository to something else.
You wanted to say

Find {MAVEN_HOME}\conf\setting.xml, update localRepository to something else.

Or it is correct?
Thanks :)

Rajesh
Guest
Rajesh

Exactly !!!

RoarLion
Guest
RoarLion

both are same M2_HOME= MAVEN_HOME

Yoesoff
Guest
Yoesoff

simple and helpful, thanks

trackback
Where is maven central repository? | Yêu công ngh? dot com

[…] which dependency to download. First, Maven will get the dependency from your local repository Maven local repository, if not found, then get it from the default Maven central repository – […]

Oskar
Guest
Oskar

Hi there
I’m quite new to maven and I’ve been trying to rotate the location of the settings.xml file, as I need it under version control, thus in a specific directory.
So far I tried “export MAVEN_OPTS=-Dorg.apache.maven.user-settings=/path/to/directory/settings.xml”
But unfortunatly that doesn’t work. It tried this because it works with switching the local repo with “export MAVEN_OPTS=-Dmaven.local.repo=/path/to/repo”.
Does anybody know how this could be accompished without using “mvn -s /path/to/directory/settings.xml someplugin:someGoal” ? Any hints, tips, tricks would be great,…. google could not really solve this… :(

Cheers Oskar

Natwar Sharma
Guest
Natwar Sharma

Short and sweet.Thanks alot man!!

trackback
How to create a Java project with Maven

[…] again, Maven will download the plugins and project dependencies and store it into your local Maven repository […]

trackback
How to download from Maven remote repository?

[…] Maven, when you’re declared library does not exist either inlocal repository nor Maven center repository, the process will stop and output error messages to your Maven […]

Satya Marrapu
Guest
Satya Marrapu

Hi yong i’m doing what you were specify in tutorial, but i’m getting BUILD-ERROR.

How to resolve that, plz help me

sumit das
Guest
sumit das

Thanks. Simple and clear description.

Keep up the good work.

Younus
Guest
Younus

Still am not getting the repo folder

RoarLion
Guest
RoarLion

go to the the C:Documents and SettingsYour User folder .m2

RoarLion
Guest
RoarLion

Hi younus,

may be few reasons.

And check for the maven home environment variable has set . if not do it correctly.
check whether you have any other maven installation in your machine. after you setting the

environment and path variables restart the machine.
for my case I had a previous maven installation and repo folder created according to that setting file local repository location. (although when I type mvn –version it shown the current maven directory ).
Then I restarted and now working fine.

Reddy
Guest
Reddy

Hi,
im new to maven

Help me
how create a .m2 directory in c:users/directory

Rafa
Guest
Rafa

Is there a typo in the text for “settings.xml”? I think the line:

<localRepository>D:/maven_repo</localRepository>

should read:

<localRepository>D:/maven/repo</localRepository>

based on the directory structure you displayed in the image.

William
Guest
William

I was even second guessing whether Maven translated _ to / or something, until I read your comment.

marcos
Guest
marcos

Short and clean. Thanks a lot!!

trackback
Maven Tutorials | J2EE Web Development Tutorials

[…] Maven local repository Maven local repository is used to store the project dependency libraries, and the default folder is “.m2″, you may need to change it to another folder. […]

trackback
How to create a project with Maven template | Maven

[…] really magic, Maven will download all the necessary project’s dependency libraries in your Maven’s local repository, all newly created project’s files and folders in your current file path , […]

Nagesh
Guest
Nagesh

Very info.
I’m follower of your blog/sites of Java. Thanks a lot for your efforts to make my life easy.