maven3.8.1安装及配置流程

本文详细介绍了如何在Windows环境下安装和配置Maven3.8.1,包括解压安装包、配置环境变量、验证安装以及定制settings.xml文件,特别是设置了本地仓库路径和阿里云镜像仓库,确保离线状态下也能正常工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

maven3.8.1安装及配置流程

1、解压apache-maven-3.8.1-bin.zip到指定目录
  • 我这里是解压到:C:\sofeware\tools\mvn\apache-maven-3.8.1
2、配置环境变量
  • 右击此电脑–>选择属性–>高级系统设置–>选择右下角的环境变量–>选择系统变量

    –>新建MAVEN_HOME变量值就是你的maven的解压目录我这里是:C:\sofeware\tools\mvn\apache-maven-3.8.1–>找到path增加一条环境变量:%MAVEN_HOME%\bin–>保存退出;
    在这里插入图片描述

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UbDGdIVo-1627025443746)(C:\文档\md_photo\1625454103492.png)]

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7DXNoXVZ-1627025443751)(C:\文档\md_photo\1625454155681.png)]

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vrVfhWAS-1627025443758)(C:\文档\md_photo\1625454198834.png)]

3、win+r输入cmd 双击打开cmd输入mvn -v会输出以下结果

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-beIkcadQ-1627025443765)(C:\文档\md_photo\1625453924348.png)]

4、settings的配置

  • setting 文件在apache-maven-3.8.1\conf里边我的setting文件的位置是C:\sofeware\tools\mvn\apache-maven-3.8.1\conf,在修改setting文件之前需要保留副本,避免配置出错无法恢复之前的版本
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | 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
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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 http://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>
  -->
  <!--本地maven仓库地址-->
  <localRepository>C:\sofeware\tools\mvn\Respository</localRepository>

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |确定maven在执行构建时是否应尝试连接到网络。
	|这将对工件下载、工件部署等产生影响。
   | Default: false
  <offline>false</offline>
  -->
<offline>ture</offline>
  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |	这是用于从远程存储库下载工件的镜像列表。
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |	它的工作原理是这样的:POM可以声明一个用于解析某些工件的存储库。但是,此存储库有时可能会遇到流量过大的问题,因此人们已将其镜像到多个地方。
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |	该存储库定义将具有唯一的id,因此我们可以为该存储库创建镜像引用,用作备用下载站点。镜像站点将是该存储库的首选服务器。
   |-->
  <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.
     |	指定要使用的存储库镜像站点,而不是给定的存储库。
	 |  此镜像服务的存储库的ID与此镜像的mirrorOf元素匹配。ID用于继承和直接查找,并且在镜像集中必须是唯一的。
    <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>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |	这是一个概要文件列表,可以以多种方式激活,并且可以修改构建过程。
   |    在settings.xml中提供的概要文件旨在提供本地机器特定的路径和存储库位置,这些路径和位置允许构建在本地环境中工作。
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |	例如,如果您有一个集成测试插件(如cactus),
   |    它需要知道Tomcat实例的安装位置,那么您可以在这里提供一个变量,以便在构建过程中取消对该变量的引用以配置cactus插件。
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |	如上所述,配置文件可以通过多种方式激活。
   |   其中一种方法——本文档的activeProfiles部分(settings.xml)——将在后面讨论。
   |   另一种方法本质上依赖于系统属性的检测,或者匹配属性的特定值,或者仅仅测试其存在性。
   |	配置文件也可以由JDK version prefix激活,其中值为“1.4”的配置文件可能会在JDK版本“1.4.2\u 07”上执行生成时激活配置文件。
   |    最后,可以直接从命令行指定活动概要文件的列表。
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |	对于在settings.xml中定义的概要文件,您只能指定工件存储库、插件存储库和自由格式属性作为POM中插件的配置变量。
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |	指定要使用上述一个或多个机制激活的生成过程的一组介绍。
	 |	出于继承目的,要通过<activatedProfiles/>或命令行激活配置文件,配置文件必须具有唯一的ID。
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |	配置文件标识的一个受鼓励的最佳实践是对配置文件使用一致的命名约定,
	 |		例如“env dev”、“env test”、“env production”、“user jdcasey”、“user brett”等。
	 |	这将使您更直观地了解引入的配置文件集试图完成的任务,尤其是当您只有一个用于调试的配置文件id列表时。
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->
      <!-- 这一段必须加上-->
		<profile>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>createdbymyself</name>
                    <url>http://maven.oschina.net/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>createdbymyself</name>
                    <url>http://maven.oschina.net/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
		
		<!--jdk配置-->
		<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>
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

ance


–>


### Maven 3.8.1 的下载、安装配置教程 #### 下载 Maven 3.8.1 对于 Linux 系统(CentOS 7),可以通过命令行工具 `wget` 来获取 Apache Maven 的二进制压缩包。执行以下命令完成下载操作: ```bash sudo wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz ``` 此命令会将指定版本的 Maven 压缩包下载到当前工作目录下[^1]。 而对于 Windows 用户,则需手动访问官方镜像站点或者直接通过浏览器打开链接地址,随后点击保存按钮至本地硬盘中的自定义路径位置,比如 D:\developsoftware\maven3.8.1 文件夹内[^2]。 #### 解压与移动文件 在 CentOS 上继续处理刚才获得的数据包之前先解压它,并将其放置于合适的位置上以便后续调用方便快捷: ```bash tar -zxvf apache-maven-3.8.1-bin.tar.gz sudo mv apache-maven-3.8.1 /usr/local/ ``` 上述两条指令分别完成了对 tarball 归档形式资源提取以及重定位存储过程的操作说明文档中提到过的内容;而在 windows 平台这边只需要利用 WinRAR 或者其他支持相同功能的应用程序来实现同样的目的即可。 #### 设置环境变量 为了能够在任何地方都能轻松启动 Maven 工具,在两套操作系统里都需要设置一些必要的全局参数项。 ##### 对于 CentOS: 编辑 profile 配置脚本加入新的 PATH 变量声明部分如下所示: ```bash vi ~/.bashrc export MAVEN_HOME=/usr/local/apache-maven-3.8.1 export PATH=$PATH:$MAVEN_HOME/bin source ~/.bashrc ``` 这里我们修改用户的 shell 初始化文件(.bashrc),增加两个导出语句用于指明 maven 主目录及其可执行命令所在子目录的具体物理地址信息,最后记得重新加载该配置使其生效. ##### 关于 Window : 同样也需要调整系统的高级属性界面下的“环境变量”选项卡里的相关内容设定。具体做法是在系统级别新增名为 MAVEN_HOME 的键值关联关系指向实际存放软件副本的目标盘符加完整相对应路劲字符串表达式例如:D:\developsoftware\maven3.8.1; 同时追加 %MAVEN_HOME%\bin 至现有的 Path 列表末端处. 至此为止你应该已经成功部署好了最新稳定发行版的 Maven 构建管理框架啦!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值