MAVEN 学习日记(三)之 MAVEN 的下载和配置

MAVEN 学习日记(三)之 MAVEN 的下载和配置

maven 下载

maven 官网:http://maven.apache.org/

maven 环境配置

须配置 JAVA_HOME 和 MAVEN_HOME(因为 mvn 运行时会使用 JAVA_HOME 和 MAVEN_HOME 这两个路径变量)

在命令行窗口运行 mvn, 出现 mvn 的提示就表示配置成功

本地仓库配置

在磁盘中选择一个文件夹作为本地仓库,我这里选择的是 D 盘下的 maven 文件夹的 repository 文件夹

打开 maven 安装目录中的 conf 文件夹,打开 setting.xml 对其进行修改

仓库位置配置

maven 默认是在 C:/users/用户名/.m2/repository 文件夹中,但由于一般 C 盘是作为系统盘,故要自定义位置

在 setting.xml 中找到

<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.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>
  -->

把注释中的

<localRepository>/path/to/local/repo</localRepository>

复制出来并改为

<localRepository>你自定义的仓库位置的路径</localRepository>

仓库镜像配置

由于 maven 默认是直接从中央仓库拉取 jar 包的,但中央仓库比较慢,故须配置镜像

在 setting.xml 中找到

<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>
     -->
</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>
    </mirror>

注意一定要在</mirrors>前面

自此配置完成,可以愉快的使用 maven 了

posted @ 2022-11-15 09:36  czwang7242  阅读(40)  评论(0)    收藏  举报