Home » Maven » Maven Repository Introduction

Maven Repository Introduction

What is Maven Repository ?

To resolve the dependency of a project Maven requires multiple JARs (Framework specific Jars or Project Jars), plugins or any other project specific artifacts are stored and can be used by Maven easily. Maven will look for these Jars in certain locations, these locations are called Repository (Maven Specific Terminology).

Maven has 3 different type of repository.

  • Local Repository
  • Central Repository
  • Remote Repository

Local Repository :

Maven local repository is a folder on local system which is used to store project's dependencies (Jars). Whenever you try to build a project Maven will try to download all the required Jars in Local Repository.

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

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

How to change Maven Local Repository:

To change the location of Default Local Repository you need to change the maven's "settings.xml", which will be located @ %M2_HOME%\conf.
update localRepository to your desired path like D:/maven_repo.

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

Central Repository :

When you build a Maven's project, Maven will check your pom.xml file, to identify 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 -http://repo1.maven.org/maven2/

Remote Repository :

Sometime, Maven does not find a mentioned dependency in central repository as well then it stopped build process and output error message to console. To prevent such situation, Maven provides concept of Remote Repository which is developer's own custom repository containing required libraries or other project jars.
For example, using below mentioned POM.xml,Maven will download dependency (not available in central repository) from Remote Repositories mentioned in the same pom.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0"

Previous Next Article

comments powered by Disqus