Maven - Repository (repository)

Copyright unauthorized, prohibited reproduced


chapter


Maven Repository / Repository, as the name suggests is a warehouse to store JAR file, Maven dependency information jar package according to the project pom.xml file provided from the repository to find and obtain the required jar package.

Maven Repository There are three types:

  • Local Repository - the local library
  • Central Repository - Central Library
  • Remote Repository - the remote repository

Search Maven dependencies will follow: the order in local libraries, the Central Library and remote libraries.

image

If you did not find these libraries dependencies, Maven will report an error.

1. Local Repository

Maven local repository is a directory of the machine. If the directory does not exist, the implementation of maven will create it.
By default, maven local repository is a %USER_HOME%/.m2directory, for example:C:\Users\Kevin\.m2

Local repository directory settings

You can change the location maven local repository by modifying the settings.xml file.

settings.xml file is located MAVEN_HOME/conf/settings, for example: D:\opt\apache-maven-3.6.1-bin\apache-maven-3.6.1\conf\settings.xml.

settings.xml the default configuration:

...  
<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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  
...  
</settings> 

Modifying the local repository path, as follows:

settings.xml

...  
<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:/maven-local-repo</localRepository>  
    
...  
</settings>  

Thus, the path to the local repository was amended as follows:d:/maven-local-repo

2. Central Repository

Maven central repository major public placement jar package, created by apache maven Community at the central library is http://repo1.maven.org/maven2 , by URL http://search.maven.org/#browse View What are the common jar package.

3. Remote Repository

Maven remote repository library is located on the network. For example, a company may have a lot to share a jar file, you can build a house in a remote database, for many developers to use; a central repository can be considered a special remote library.

You can configure the remote repository in pom.xml, add the following to the pom.xml to configure a remote database (just an example, invalid remote library URL):


  <repositories>
   <repository>
       <id>qikegu.code</id>
       <url>http://maven.qikegu.com/maven2/lib</url>
   </repository>
 </repositories>
  

Maven official website mvnrepository.com can find the jar package and related information, for example, the following is a maven spring core jar package depends on the configuration information, you can get spring core jar by these configurations.

<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.1.6.RELEASE</version>
</dependency>

Guess you like

Origin blog.csdn.net/weixin_43031412/article/details/91956094