Maven Repository


A maven repository is an index of bundled JAR record with pom.xml document. maven scans for dependencies in the stores. There are 3 sorts of maven repository:

  1. Local Repository
  2. Central Repository
  3. Remote Repository

Maven looks for the dependencies in the accompanying order:

Local repository then Central repository then Remote repository.

maven repositories

If dependency isn't found in these archives, maven quits preparing and tosses an error.


1) Maven Local Repository

Maven local repository is located in your local framework. It is made by the maven when you run any maven command.

By default, maven nearby archive is %USER_HOME%/.m2 index. For instance: C:\Users\SSS IT\.m2.

h2 class="h4">Update location of Local Repository

We can change the location of 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 settings.xml file.

settings.xml
  1. ...  
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   
  3.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  5.   <!-- localRepository  
  6.    | The path to the local repository maven will use to store artifacts.  
  7.    |  
  8.    | Default: ${user.home}/.m2/repository  
  9.   <localRepository>/path/to/local/repo</localRepository>  
  10.   -->  
  11.   
  12. ...  
  13. </settings>  

Now change the way to nearby store. In the wake of changing the way of local repository, it will look like this:

settings.xml
  1. ...  
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   
  3.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  5.    <localRepository>e:/mavenlocalrepository</localRepository>  
  6.     
  7. ...  
  8. </settings>  

As you can see, now the path of local repository is e:/mavenlocalrepository.

2) Maven Central Repository

Maven central repository is located on the web. It has been made by the apache maven community itself.

The way of focal vault is: http://repo1.maven.org/maven2/.

The focal vault contains a great deal of basic libraries that can be seen by this url http://search.maven.org/#browse.


3) Maven Remote Repository

Maven remote repository is located on the web. The Most majority of libraries can be absent from the focal archive, for example, JBoss library and so forth, so we have to characterize remote repository in pom.xml file.

Let's see the code to include the jUnit library in pom.xml file.

div class="codeblock">
  1. <project xmlns="http://maven.apache.org/POM/4.0.0"   
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   
  4. http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.   
  6.   <modelVersion>4.0.0</modelVersion>  
  7.   
  8.   <groupId>com.javacodegeeks.application1</groupId>  
  9.   <artifactId>my-application1</artifactId>  
  10.   <version>1.0</version>  
  11.   <packaging>jar</packaging>  
  12.   
  13.   <name>Maven Quick Start Archetype</name>  
  14.   <url>http://maven.apache.org</url>  
  15.   
  16.   <dependencies>  
  17.     <dependency>  
  18.       <groupId>junit</groupId>  
  19.       <artifactId>junit</artifactId>  
  20.       <version>4.8.2</version>  
  21.       <scope>test</scope>  
  22.     </dependency>  
  23.   </dependencies>  
  24.   
  25. </project>  

You can search any repository from Maven official website mvnrepository.com.






javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition