当前位置:   article > 正文

【Maven】002-Maven 安装和配置_maven home

maven home

【Maven】002-Maven 安装和配置

一、官网

1、官网

https://maven.apache.org/

image-20240113092135762

2、历史版本列表

https://maven.apache.org/docs/history.html

image-20240113092100219

3、Maven 仓库地址

https://mvnrepository.com/

二、下载 Maven 3.8.8 版本

1、进入 Maven 3.8.8 版本发行说明页

历史版本列表:https://maven.apache.org/docs/history.html

image-20240113092350967

2、进入下载页

image-20240113092525920

3、下载

image-20240113092717678

4、下载得到 apache-maven-3.8.8-bin.zip

image-20240113092846041

三、Maven 安装

Maven 需要本机安装 Java 环境、必需包含 JAVA_HOME 环境变量!

1、将安装包解压到想放置的目录即可

image-20240113093031840

2、目录结构简介

bin:含有 Maven 的运行脚本;

boot:含有 plexus-classworlds 类加载器框架;

conf:含有 Maven 的核心配置文件;

lib:含有 Maven 运行时所需要的 Java 类库;

LICENSE、NOTICE、README.txt:针对 Maven 版本,第三方软件等简要介绍。

四、Maven 环境配置

1、第一步:配置 MAVEN_HOME

新建系统变量

变量名:MAVEN_HOME

变量值:D:\MySoft\Environment\Maven\apache-maven-3.8.8(解压的目录)

image-20240113094735365

2、第二步:配置环境变量(Path)

新增:%MAVEN_HOME%\bin

image_xNL5Fg_ucf

3、第三步:Maven 命令测试

mvn -v

image-20240113095728445

五、Maven 功能配置

1、概述

主要修改的内容

我们需要修改 conf/settings.xml 配置文件,来修改 maven 的一些默认配置。

主要修改的有三个配置:

  1. 依赖本地缓存位置(本地仓库位置);
  2. maven 下载镜像;
  3. maven 选用编译项目的 jdk 版本。

文件位置图

image-20240113100352917

2、配置本地仓库地址

image-20240113101420621

3、配置阿里云镜像

代码

    <!-- 阿里云镜像源 -->
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

截图

image-20240113102000565

华为鲲鹏等参考

https://mirrors.huaweicloud.com/home

https://mirrors.huaweicloud.com/mirrorDetail/5fbb71cd07bbb121c2aded7b

使用说明:

本镜像仅包含兼容 aarch64 环境的 jar 包,不是完整的 Maven 中央仓库,需要配置其他 Maven 中央仓库一起使用,例如华为云Maven。
使用前,参考如下内容修改**<Maven安装目录>/conf/settings.xml**文件:

<profile>
    <id>kunpeng</id>
    <!-- 远程仓库列表,将华为鲲鹏 Maven 仓库放在最前面 -->
    <repositories>
        <repository>
            <id>kunpengmaven</id>
            <name>kunpeng maven</name>
            <url>https://repo.huaweicloud.com/kunpeng/maven/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <!-- 其他 repository,配置其他Maven中央仓库,以华为云Maven为例 -->
        <repository>
            <id>huaweicloud</id>
            <name>huaweicloud maven</name>
            <url>https://repo.huaweicloud.com/repository/maven/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
</profile>
<!-- 激活上面的profile -->
<activeProfiles>
  <activeProfile>kunpeng</activeProfile>
</activeProfiles>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
    <profile>
      <id>kunpeng</id>
      <!-- 远程仓库列表,将华为鲲鹏 Maven 仓库放在最前面 -->
      <repositories>
          <repository>
              <id>kunpengmaven</id>
              <name>kunpeng maven</name>
              <url>https://repo.huaweicloud.com/kunpeng/maven/</url>
              <releases>
                  <enabled>true</enabled>
              </releases>
              <snapshots>
                  <enabled>true</enabled>
              </snapshots>
          </repository>
          <!-- 其他 repository,配置其他Maven中央仓库,以华为云Maven为例 -->
          <repository>
              <id>huaweicloud</id>
              <name>huaweicloud maven</name>
              <url>https://repo.huaweicloud.com/repository/maven/</url>
              <releases>
                  <enabled>true</enabled>
              </releases>
          </repository>
          <repository> 
              <id>alimaven</id>
              <name>aliyun maven</name>
              <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          </repository>
          <repository> 
              <id>activiti-repos2</id> 
              <name>Activiti Repository 2</name> 
              <url>https://app.camunda.com/nexus/content/groups/public</url> 
          </repository>
          <repository> 
              <id>activiti-repos</id> 
              <name>Activiti Repository</name> 
              <url>https://maven.alfresco.com/nexus/content/groups/public</url> 
          </repository> 
      </repositories>
</profile>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

4、配置 JDK 版本

代码

    <profile>
      <id>jdk-17</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>17</jdk>
      </activation>
      <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
      </properties>
    </profile>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

截图

image-20240113102151314

激活 profile

  <!-- 激活上面的profile -->
  <activeProfiles>
    <activeProfile>jdk-17</activeProfile>
  </activeProfiles>
  • 1
  • 2
  • 3
  • 4

激活 profile 截图

image-20240113102736938

六、IDEA 配置 Maven

image-20240113103004765

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/929861
推荐阅读
相关标签
  

闽ICP备14008679号