In this article, we will learn about different types of maven repositories. In simple, maven repositories contains packaged JARS of various modules
1. Maven Repositories:
Three types of Maven repository are
- Local Repository
- Central Repository
- Remote Repository
Maven searches dependencies in the following order
Source: Team BenchResources.net
1.1 Local Repository
Local repository is the local directory on the developer’s computer. Generally, when you run maven command for the first time it downloads all dependent JARS from Central/Remote repositories and store in the default location
The default location is
C:\Users\<user-name>\.m2\repository
If one wishes to change the default location to some user-defined location then you do by changing the <localRepository> element present in the settings.xml at MAVEN_HOME\conf\settings.xml
Update location with absolute path
<localRepository D:\M2_HOME\.m2\repository</localRepository>
New maven settings.xml
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository D:\M2_HOME\.m2\repository</localRepository>
Note: For the very first time it downloads packages JARS from either Central or Remote repository, from next time onwards it picks JARS from local repository i.e.; local directory of the developer’s computer even for different project
1.2 Central Repository
Central maven repository is located on the web at http://repo1.maven.org/maven/ and it is provided by Maven community
Note: First time, maven tries to download most of the JARS from this central repository
This site is now revamped and “Directory Browsing” is disabled at http://repo1.maven.org/maven/ and instead it re-directs to new site
This new site is much more advanced and has good browse functionality –> click View
1.3 Remote Repository
As shown in the first figure above, if the required JARS is not available in Local repository or Central repository then maven checks if there are any remote repository is configured else it stops and throws error
For example, JBoss dependencies are configured in pom.xml
pom.xml
<!-- RESTEasy JAX RS Implementation -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
<scope>${resteasy.scope}</scope>
</dependency>
But if these JARS are not available in Central repository, and then in that case you need to tell maven to search and download these JARS from Remote repository configured in pom.xml
pom.xml
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
2. Maven dependencies checking rules
- Maven searches to download dependencies from Local Repository, if not found next step
- Maven searches to download dependencies from Central Repository, if not found checks whether any remote repositories are configured then go to next step otherwise stops & throws error
- Maven searches to download dependencies from the configured Remote Repository, if found then download and do further processing otherwise stops & throws error
Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
Happy Coding !!
Happy Learning !!