Repository
If we use Dependencies in MAVEN Project then MAVEN will search for the dependent JARs in Repositories. MAVEN will use three types of Repositories in order to get dependencies.
1. Local Repository
It is a location to manage and supply all dependencies, it will be created by MAVEN when we execute any MAVEN command first time. In general, MAVEN will create Local Repository at “C:/Users/User_Name/.m2/ repository”
E.g.
C:\Users\ashok.mariyala\.m2\repository
2. Central Repository
It is a default Repository for MAVEN, it is located at “http:// repo1.maven.org/maven2”. In MAVEN applications, we will use some other repositories are also explicitly like.
- http://repository.jboss.org/nexus/content/groups/public
- http://mvnrepository.com
In MAVEN applications, if we want to use the above explicit repositories then we have to configure them in pom file by using the following xml tags.
<repositories> <repository> <id>jboss</id> <name>jboss repo</name> <url>http://repository.jboss.org/nexus/content/groups/public/</url> </repository> </repositories>
3. Remote Repository
In some Situations, Maven does not find the dependencies in Local Repository and in central repository, in this context, MAVEN stops the build process and generates some Exceptions. To overcome these problems, Maven has provided a new Features like “Remote Repository”.
Remote Repository is a developer’s own custom repository containing required libraries or other project jars. To configure Remote Repository, we have to use the following XML tags in pom.xml file.
<repositories> <repository> <id>ashok.lib</id> <url>http://library.ashok.com/maven2/lib</url> </repository> </repositories>
When we run MAVEN project then MAVEN will search for the dependencies in the following order.
1. First, MAVEN will search for the dependencies in local repository, if the required dependencies are available at Local Repository the MAVEN will use them in application. If the dependencies are not available at Local Repository then MAVEN search for them at Central Repository.
2. If the required Dependencies are existed in central repository then MAVEN will load them into Local Repository and MAVEN will use them in the applications. If the required dependencies are not existed in Central Repository then MAVEN will search for them in Remote Repositories as per configuration.
3. If Remote Repository is not configured then MAVEN will stop the application execution and generated some Exceptions.
4. If Remote Repository is configured then MAVEN will search for the required dependencies in Remote Repository, if they are identified then MAVEN will load them into Local Repository for future reference. If the dependencies are not existed at Remote Repositories then MAVEN will stop the execution and generate some Exceptions.