How to change Maven local repository

Windows 7 becomes very slow once the profile size increases. For better performance it should be less than 2 GB. By default default location of maven repository is inside user directory which increases user profile size and makes the computer very slow. The better option is to configure maven respiratory out side the user directory and increase your windows 7 performance.  Follow this post, it might help :

Maven local repository is used to store all your projects’ dependency libraries (plugin jars and other files which downloaded by Maven), . In simple, when you use Maven to build your project, it will automatically download all dependency libraries into your Maven local repository.

Maven local repository is default to home directory :

Unix/Mac OS X – ~/.m2 on
Windows – C:\Documents and Settings\username\.m2 on Windows
Often times, you need to change the default location for maintainability purpose, after all, the .m2 is not a meaningful name.

1. Maven configuration file

Maven local repository is defined in the Maven’s configuration file, for example, {M2_HOME}\conf\setting.xml.
2. Edit it “setting.xml”

Find the following “localRepository” pattern, and define your new Maven local repository inside the “<localRepository>” element like this :

<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>
… <settings>
3. Saved it

Done, your new Maven local repository is now changed to D:/maven_repo, all the future project’s dependency libraries or related files will be downloaded into this folder. See following folder :

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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.