11.6. Maven warehouse

发布时间 : 2025-10-25 13:35:09 UTC      

Page Views: 9 views

In Maven terminology, a warehouse is a place.

The Maven repository is the third-party library that the project depends on, and the location of this repository is called the repository.

In Maven, the output of any dependency, plug-in, or project build can be called a component.

The Maven repository helps us manage artifacts (mainly JAR), which is where all the JAR files (WAR,ZIP,POM, etc.) are placed.

There are three types of Maven repositories:

  • Local (local)

  • Central (central)

  • Remote (remote)

11.6.1. Local warehouse

Maven’s local repository is not created after Maven is installed, it is created the first time the maven command is executed.

When running Maven, any artifacts required by Maven are obtained directly from the local repository. If the local warehouse does not, it will first try to download the artifacts from the remote warehouse to the local warehouse, and then use the artifacts from the local warehouse.

By default, regardless of Linux or Windows, each user has a repository directory with a path name of .m2 / repository/ under his or her own user directory.

The Maven local warehouse is created under the% USER_HOME% directory by default. To change the default location, define another path in the settings.xml file of Maven in the% M2roomHOME%conf directory.

<settingsxmlns="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">C:/MyLocalRepository 

When you run the Maven command, Maven will download the dependent files to the path you specified.

11.6.2. Central warehouse

The Maven Central Warehouse is a repository provided by the Maven community that contains a large number of commonly used libraries.

The central repository contains most of the popular open source Java artifacts, as well as source code, author information, SCM, information, license information, and so on. In general, simple Java projects rely on artifacts that can be downloaded here.

Key concepts of a central warehouse:

  • The warehouse is managed by the Maven community.

  • No configuration is required.

  • It needs to be accessed through the network.

To browse the contents of the central repository, the maven community provides a URL: http://search.maven.org/#browse . Using this repository, developers can search all available code bases.

11.6.3. Remote warehouse

If Maven also cannot find the dependent file in the central repository, it stops the build process and outputs the error message to the console. To avoid this, Maven provides the concept of a remote warehouse, which is customized by developers to include the required code base or other jar files used in the project.

For example, using the following pom.xml,Maven will download the dependent files declared in the pom.xml (not available in the central repository) from the remote repository.

<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0com.companyname.projectgroupproject1.0com.companyname.common-libcommon-lib1.0.0companyname.lib1http://download.companyname.org/maven2/lib1companyname.lib2http://download.companyname.org/maven2/lib2     

11.6.4. Maven depends on search order

When we execute the Maven build command, Maven starts looking for dependent libraries in the following order:

  • 步骤 1 -search in the local warehouse, if it is not found, perform step 2, and if found, perform other actions.

  • 步骤 2 -search in the central warehouse, if it cannot be found, and one or more remote warehouses have been set up, perform step 4, and if found, download it to the local warehouse for future reference.

  • 步骤 3 -if the remote repository is not set up, Maven will simply stagnate and throw an error (the dependent file cannot be found).

  • 步骤 4 -search for dependent files in one or more remote repositories, and if found, download them to the local repository for future reference, otherwise Maven will stop processing and throw an error (dependent files cannot be found).

11.6.5. Maven Aliyun (Aliyun) warehouse

Maven warehouse default in foreign countries, domestic use is inevitably very slow, we can replace it with Aliyun warehouse.

Modify the settings.xml file in the conf folder under the maven root directory, and on the mirrors node, add the following:

<mirror><id>aliyunmavenid><mirrorOf>\*mirrorOf><name>阿里云公共仓库name><url>https://maven.aliyun.com/repository/publicurl>mirror>    

If you want to use other proxy repositories, you can add the corresponding warehouse usage address in the < repositories > < / repositories > node. Take the use of spring proxy warehouse as an example:

<repository><id>springid><url>https://maven.aliyun.com/repository/springurl><releases><enabled>trueenabled>releases><snapshots><enabled>trueenabled>snapshots>repository>    

Add the file information you want to reference in your pom.xml < denpendencies > < / denpendencies > node:

<dependency><groupId>[GROUP_ID]groupId><artifactId>[ARTIFACT_ID]artifactId><version>[VERSION]version>dependency>    

Execute the pull command:

mvn install 

11.6.6. Gradle configuration Guid

Add the following code to the build.gradle file:

allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/public/' } mavenLocal() mavenCentral() } } 

If you want to use another proxy warehouse, take the spring warehouse as an example, the code is as follows:

allProjects { repositories { maven { url 'https://maven.aliyun.com/repository/public/' } maven { url 'https://maven.aliyun.com/repository/spring/' } mavenLocal() mavenCentral() } } 

Add the file information you want to reference:

dependencies { compile '[GROUP_ID]:[ARTIFACT_ID]:[VERSION]' } 

Execute the following command to install dependencies:

gradle dependencies  ./gradlew dependencies 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。