Tuesday, March 29, 2011

Using Maven from a local repository

Maven has a local repository. Local repository is used to store all the projects' libraries. When you build your application with maven by your build script maven will download all the depended libraries to your local repository. But if you are behind a corporate firewill and do not have access to a proxy you can download all the libraries first at home and tell maven to use those local libraries.

Maven local repository is default to home directory (~/.m2 on Unix/Mac OS X and C:\Documents and Settings\username\.m2 on Windows). Often times, you need to change the default location for maintainability purpose, .m2 is not a meaningful name:).

Maven configuration file
This file is under {M2_HOME}\conf\setting.xml
Location of the local repository is definfed in this file.

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

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

Maven will use this local repository location. If maven finds all the libraries on the local drive it will not try to download them from an online repository.

LinkWithin

Related Posts Plugin for WordPress, Blogger...