Maven基础概念

仓库

仓库用于存储资源,包含各种jar包。

仓库分类:

  • 本地仓库:自己电脑作为仓库,连接远程仓库获取资源。
  • 远程仓库:非本地的仓库,为本地仓库提供资源。

                中央仓库:由Maven团队维护,存储开源资源的仓库,地址:Central Repository

                私服:部门或者公司范围内存储资源的仓库,从中央仓库获取资源

 私服的作用:

        保存具有版权的资源,包括购买和自主研发的jar。

        一定范围内共享资源,仅对内部开放,不对外共享。

坐标

什么是坐标

maven中的坐标用于描述资源在仓库中的位置,由一些标签组成。

Maven坐标的主要组成

        groupId:定义当前项目属于哪个组织,通常是域名反写。groupId不一定要与主包名相符,但建议一样。

        artifactId:定义当前项目名称,通常是模块名称,例如CRM、SMS

        version:定义当前项目的版本号

        packaging:定义当前项目的打包方式

哪里查询资源的坐标

1、https://mvnrepository.com/

2、Maven搜索-最快捷的Maven搜索-由源码阅读网提供技术服务

maven坐标的作用

使用唯一标识,唯一性定位资源位置,通过该标识可以将资源的识别与下载交给机器完成。

本地仓库配置

打开MAVE_HOME/conf/settings.xml ,配置本地仓库位置,如下:

默认位置

${user.home}/.m2/repository

将当前登录用户名所在目录下的.m2文件夹下的repository文件夹作为仓库

自定义位置

<localRepository>D:/repository</localRepository>

远程仓库配置

 maven默认连接的仓库位置,但从该仓库中下载资源太慢,所以不用,用阿里云镜像仓库。

<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

镜像仓库配置

由于从中央仓库下载资源太慢,所以在setting.xml中配置阿里云镜像仓库,之后我们就可以从镜像仓库中下载资源。

<mirrors>
	<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/public</url>
      <!-- 对中央仓库进行镜像,简单说就是代替中央仓库-->
      <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

全局 setting 与用户 setting

全局setting:在 maven 安装目录下的 conf/setting.xml 文件作为全局配置 ,定义了当前计算机中maven的公共配置。
用户setting:如需要个性配置则需要在用户配置中设置,用户配置的 setting.xml 文件默认的位置在:${user.dir} /.m2/settings.xml 目录中 ,${user.dir} windows 中的用户目录。
maven 会先找用户配置,如果找到则以用户配置文件为准,否则使用全局配置文件。
可以参考setting.xml中的这段话:
| This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值