Maven - Maven Repository- maven tutorial



maven tutorial tags : apache maven , maven repository , maven central

What is Repository in Maven ?

  • For maven to download the required artifacts of the build and dependencies (jar files) and other plugins which are configured as part of any project.
  • There should be a common place where all such artifacts are placed.
  • This common shared area is called as Repository in maven.
  • learn maven tutorial - apache maven - maven repository maven workflow - Apache Maven example programs

    learn maven tutorial - apache maven - maven repository maven workflow - Apache Maven example programs

  • In maven, repositories are classified into 3 main categories as shown below:
    • Local Repository
    • Remote Repository
    • Central Repository
 Maven Repository

Learn Maven Tutorial - Maven Repository - Maven Example

Local Repository

  • The repository which resides in our local machine which are cached from the remote/central repository downloads and ready for the usage.
  • The folder to hold/place all the dependencies in local can be configured in the settings.xml file of the maven folder under the tag <localRepository>.
maven tutorial tags : apache maven , maven repository , maven central

Sample Code

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 
          http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:/m2repo</localRepository>
</settings>

Remote Repository

  • This repository as the name suggests resides in the remote server and which can be accessed by using different file transfer protocols like file:// or http://.
  • Remote repository will be used for both downloading and uploading the dependencies and artifacts.
maven tutorial tags : apache maven , maven repository , maven central

Sample Code

<repositories>
      <repository>
         <id>remote.repository</id>
         <url>http://download.ogrname.com/maven2/</url>
      </repository>
</repositories>

Central Repository

  • This is the repository provided by maven community.
  • This repository contains large set of commonly used/required libraries for any java project.
  • Basically, internet connection is required if developers want to make use of this central repository.
  • But, no configuration is required for accessing this central repository.
maven tutorial tags : apache maven , maven repository , maven central

Sample Code

<repositories>
      <repository>
         <id>central.repository</id>
         <url>http://repo1.maven.org/maven2/</url>
      </repository>
</repositories>

Organization of Local and Remote/Central Repositories

How does Maven searches for Dependencies?

  • Basically, when maven starts executing the build commands, maven starts for searching the dependencies:
  • It scans through the local repositories for all the configured dependencies.
  • If found, then it continues with the further execution.
  • If the configured dependencies are not found in the local repository, then it scans through the central repository.
  • If the specified dependencies are found in the central repository, then those dependencies are downloaded to the local repository for the future reference and usage.
  • If not found, then maven starts scanning into the remote repositories.
  • If no remote repository has been configured, then maven will throw an exception saying not able to find the dependencies & stops processing.
  • If found, then those dependencies are downloaded to the local repository for the future reference and usage.
learn maven tutorial - maven project - apache maven - Maven Repositories schema - Apache Maven example programs

learn maven tutorial - maven project - apache maven - Maven Repositories schema - Apache Maven example programs


Wikitechy provides an indepth knowledge on the below maven tutorial items such as maven download , maven install , maven goals , maven build , maven commands , maven plugin , maven search , maven eclipse , maven deploy , eclipse maven , maven junit , maven java , hibernate maven , maven project , java maven , maven version , maven proxy , maven 2 , maven pom , maven eclipse plugin , maven java version , maven properties , maven install windows , how to create maven project in eclipse , eclipse maven plugin , maven dependencies , what is maven in java , maven apache , maven project structure , how to install maven in eclipse

Related Searches to Maven Repository