Guide to Maven Repository

A maven repository is a directory of packaged JAR files with the pom.xml file. Maven searches for dependencies in the repositories. 
There are 3 types of maven repositories:
  • Local Repository
  • Central Repository
  • Remote Repository
  1. Local Repository – Folder location on the local Dev machine
  2. Central Repository – Repository provided by Maven community
  3. Remote Repository – Organization owned custom repository
Maven searches for the dependencies in the following order:
Local repository -> Central repository -> Remote repository.

In simple words, when we run a Maven build, all the dependencies of our project (jars, plugin jars, other artifacts) are all stored locally for later use.

2. Types of Maven Repository

2.1. The Local Repository

The local repository of Maven is a folder location on the developer’s machine, where all the project artifacts are stored locally.
When maven build is executed, Maven automatically downloads all the dependency jars into the local repository.
Usually, this folder is named .m2.
Here’s where the default path to this folder is – based on OS:
  • Windows: C:\Users<User_Name>.m2
  • Linux: /home/<User_Name>/.m2
  • Mac: /Users/<user_name>/.m2
And of course, for both on Linux or Mac:
  • Linux/Mac: ~/.m2
How to change the location of the Local Repository?
We can change the location of the maven local repository by changing the settings.xml file. It is located in MAVEN_HOME/conf/settings.xml, for example, E:\apache-maven-3.1.1\conf\settings.xml.
Let's see the default code of the settings.xml file:
<settings xmlns=""   
  <!-- localRepository  
   | The path to the local repository maven will use to store artifacts.  
   | Default: ${user.home}/.m2/repository  
Now change the path to the local repository. After changing the path of the local repository, it will look like this:
<settings xmlns=""   
As you can see, now the path of the local repository is e:/mavenlocalrepository.

2.2 Maven Central Repository

Maven's central repository is located on the web. It has been created by the apache maven community itself.
The path of the central repository is
The central repository contains a lot of common libraries that can be viewed by this URL

2.3 Maven Remote Repository

Maven remote repository is located on the web. Most of the libraries can be missing from the central repository such as the JBoss library etc, so we need to define a remote repository in the pom.xml file.
Let's see the code to add the JUnit library in the pom.xml file:
<project xmlns=""   
  <name>Maven Quick Start Archetype</name>  
You can search any repository from Maven's official website

3. Conclusion

In this quick guide, we had a look at the Maven local repository, central repository, and remote repository.

Read more on the Maven Developer Guide.