【Maven从入门到精通】04、Maven仓库和坐标

196 阅读1分钟

4、Maven仓库和坐标

4.1、仓库

仓库:就和我们家里的房间或者谷仓一样的概念,用于存储粮食或者物品。那么maven的仓库用来存储什么呢?答案是:存储我们项目依赖的各种jar包。

image20220720202628282png

推荐的远程仓库地址:mvnrepository.com/

4.2、仓库分类

仓库分为两种:本地仓库和远程仓库,而远程仓库分为私服和中央仓库。

image20220720203339272png

  • 远程仓库:顾名思义,是一个云端的仓库,本地仓库的所有资源都需要从远程仓库中下载。远程仓库又可以细分为私服与中央仓库。
  • 私服:作用相当于缓存,若所有的开发者都直接从中央仓库获取资源,必定造成网络阻塞,而私服就相当于缓存。私服先从中央仓库中获取所需资源,提供给本地仓库下载,一些不开源的资源也存于私服中,目的在于实现小范围的共享(内部使用)。
  • 中央仓库:收录了几乎世界上所有的jar包,本地仓库下载资源。

4.3、私服的作用

  • 保存具有版权的资源,包含购买或自主研发的jar
  • 中央仓库中的jar都是开源的,不能存储具有版权的资源
  • 一定范围内共享资源,仅对内部开放,不对外共享

4.4、配置远程仓库及阿里云镜像

在maven的安装目录下的conf/setting.xml进行如下配置:

  • 把localRepository配置打开,指定你自己的本地仓库的位置
<localRepository>/usr/local/repository</localRepository>
  • 配置阿里云的镜像仓库地址
   <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
    <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url> 
  </mirror>

配置JDK环境

 <profiles>
    <profile>  
        <id>jdk-1.8</id>  
        <activation>  
            <activeByDefault>true</activeByDefault>  
            <jdk>1.8</jdk>  
        </activation>  
        <properties>  
            <maven.compiler.source>1.8</maven.compiler.source>  
            <maven.compiler.target>1.8</maven.compiler.target>  
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
        </properties>  
    </profile>
</profiles>