windows环境下---maven的下载和配置

1. 下载https://maven.apache.org/download.cgi  ,选择windows(选择第2和4个)或者linux系统的包和资源,下载到自选目录下。(推荐使用3.6.1版本,避免后续在IDEA上有版本冲突)

    

 

2. 解压apache-maven-3.8.5-bin

3. 配置环境变量:复制上述文件夹的位置(D:\maven\apache-maven-3.8.5我的是这个)-》打开高级系统配置,选择环境变量-》新建系统变量-》输入名字和位置,点击确认-》双击path,点击新建输入%MAVEN-HOME%/bin, 点击确认。

 

 

 

 最终在终端输入指令”mvn“,出现以下情况,环境配置成果。

 

 

 

4. 电脑本身的本地仓库在C盘/用户/指定用户名下的.m2文件夹下,下图是我的本地仓库位置。考虑到我们要用maven就需要从中央仓库下各种包才能在本地调用,C盘作为系统盘,存储东西过多影响电脑性能,所以我们需要在其他盘自定义一个新的本地仓库。

 

 

 

本人的本地仓库在  D:\maven\repository

为了保证下载的资源能到自定义本地仓库中,需要修改setting文件,打开apache-maven-3.8.5下的conf文件夹,找到setting文件,用记事本打开。

 找到下面的注释代码,从下面可以看出,默认的本地仓库就是C盘下的。

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

我们需要修改成新的自定义仓库,在上述代码下,新增代码,地址根据自己新建的位置。这样本地仓库就变成了我们自己定义的了。

<localRepository>D:\maven\repository</localRepository>

5. 中央仓库是国外的,去仓库获取资源速度很慢,所以我们使用阿里云的库。

在setting中,添加新的访问地址。保存即完成配置。(如果无法下载资源到本地库,可以使用新的路径试试:http://maven.aliyun.com/nexus/content/repositories/central)

 

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>central</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      <blocked>true</blocked>
    </mirror>
  </mirrors>

 

posted @ 2022-04-01 16:12  三儿啊  阅读(536)  评论(0)    收藏  举报