Blog Archives

Change Maven repository directory within Eclipse

If you use the embedded Maven installation within Eclipse, the default .m2 directory (which contains the repository) resides in the profile of the current user.

In Windows, this is the C:\Documents and Settings\<user> directory. A large repository there could result in problems with server based profiles. Is there a quota on the server, it could be not possible to save the profile back to the server, if it contains a lot of Maven artifacts.

You can set the repository directory within the settings.xml. Copy the .m2 directory into another path on your computer (outside of your profile). Edit the settings.xml and set a new path to your repository:

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

Enter Eclipse Preferences and change the User Settings path. Click on “Update Settings” and the Local Repository should be changed to the path defined within your settings.xml. Click on “Reindex”.

Eclipse Maven Settings

Last but not least, delete the .m2 folder from your profile directory.

Proximity

I use Proximity as Maven mirror. If you need a new repository to use the artifacts for your project, you have to change three XML files to add it, which is a not easy and every time you have to copy and paste some parts of the configuration and have to change them manually. Because I’m a lazy developer I have written a script to create the necessary XML tags. You can download it from the server. Check the path of the Proximity installation within the script, per default it is set to $CATALINA_HOME/webapps/proximity. The script contains only a basic logic, you can enhance it with more complex things. The new repository will be added to the “public” repository group, which is set as the mirror within the Maven configuration file.