• 第二章 Maven-Repository存储库


    一、基本概念

    Maven Repository/存储库,顾名思义是一个存储JAR文件的仓库,Maven根据项目中pom.xml文件中提供的jar包依赖信息,从存储库中查找并获取需要的jar包。
    
    Maven Repository有3种类型:
    	# 1.Local Repository – 本地库
    	# 2.Central Repository – 中央库
    	# 3.Remote Repository – 远程库
    	
    Maven搜索依赖项时,会按照:本地库、中央库和远程库的顺序进行。
    如果这些库中没找到依赖项,Maven将报错。
    

    二、Local Repository

    Maven本地存储库是本机中的一个目录。如果目录不存在,执行maven时就会先创建它。默认情况下,maven本地存储库是%USER_HOME%/.m2目录。
    
    本地存储库目录设置
    可以通过修改settings.xml文件来更改maven本地存储库的位置。
    
    settings.xml文件位于MAVEN_HOME/conf/settings中,例如:D:optapache-maven-3.6.1-binapache-maven-3.6.1confsettings.xml。
    

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

    2.修改本地存储库路径

    ...  
    <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>  
    
    这样,本地存储库的路径就被修改为:d:/maven-local-repo
    

    三、Central Repository

    Maven中央库主要放置公共jar包,是由apache maven社区创建的,中央库的网址是http://repo1.maven.org/maven2,可以通过网址http://search.maven.org/#browse查看有哪些公共jar包。
    

    四、Remote Repository

    Maven远程库也是位于网络上的存储库。例如一个公司可能有很多共享的jar包文件,就可以搭建一个公司内部的远程库,供众多开发人员使用;中央库可以认为是一个特殊的远程库。
    
    可以在pom.xml中配置远程库,添加下面内容到pom.xml中就配置了一个远程库:
    
      <repositories>
       <repository>
           <id>test.code</id>
           <url>http://maven.fddsse.com/maven2/lib</url>
       </repository>
     </repositories>
    
    
    Maven官方网站mvnrepository.com可以查找jar包及其相关信息,例如下面是spring core jar包的maven依赖配置信息,可以通过这些配置获取spring core jar。
    
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    
  • 相关阅读:
    hive同环比实现
    hive中的to_date和to_char
    正则表达式匹配一个独立的字符
    Mysql Explain用法详解
    hadoop安装踩坑
    hadoop ssh localhost无密码登录
    Node.js第十二篇:图片随机验证码
    Node.js第十一篇:Koa框架基础
    Ajax第五篇:JQuery中使用Ajax
    Ajax第四篇:跨域JSONP、CORS
  • 原文地址:https://www.cnblogs.com/jhno1/p/15134027.html
Copyright © 2020-2023  润新知