Maven 安装及配置教程(Windows)【安装】

文章目录

  • 一、 下载
    • 1. 官网下载
    • 2. 其它渠道
  • 二、 安装
  • 三、 配置
  • 四、 验证
  • 五、 本地仓储配置
  • 六、 配置镜像
  • 七、 配置JDK
  • 八、完整配置
  • 九、常用命令
  • 十、IDEA 中配置 Maven
    • 1. 配置当前项目
    • 2. 配置新建 / 新打开 项目

软件 / 环境安装及配置目录

一、 下载

1. 官网下载

  安装地址:https://maven.apache.org/download.cgi
在这里插入图片描述

2. 其它渠道

(1)百度网盘(3.8.6 版本)

链接:链接:https://pan.baidu.com/s/1Ptregucgi3rnKN3_7_OEkw?pwd=r2as
提取码:r2as

二、 安装

  1. 下载完成后将压缩包进行解压,将解压后得到的包存放到自定义路径下,即可
    在这里插入图片描述

三、 配置

  1. 点击 我的电脑 → 右键 → 选择 属性 ,点击 高级系统设置,或者 控制面板系统和安全系统 也可以找到 高级系统设置,或者快捷键 Win + S,在输入框中输入 env,回车即可。在这里插入图片描述
  2. 点击环境变量后,跳出如下图所示对话框,第一步点击 “新建”,随后跳出 “新建系统变量” 对话框,在弹出的 新建系统变量 对话框中的 变量名 填入 maven,变量值填入 :C:\Application\Learn\maven-3.8.6(安装 解压时 Maven 所在的文件夹),点击 确定在这里插入图片描述
    在这里插入图片描述
  3. 双击打开 Path,点击新建按钮,添加变量值:%MAVEN_HOME%\bin,点击 确定
    在这里插入图片描述
    在这里插入图片描述
  4. 点击三次 确定 返回,即可
    在这里插入图片描述

四、 验证

  1. 点击 Win+R,输入 CMD 进入命令提示符界面,输入 mvn -v,假如出现如下界面则配置成功。
    在这里插入图片描述

五、 本地仓储配置

  1. 在 Maven 解压目录下,新建一个文件夹:repository(名字看个人喜欢),作为 Maven 的本地仓库
    在这里插入图片描述
  2. 在 Maven 解压目录下打开 conf 目录下的 settings.xml 文件
    在这里插入图片描述
  3. localRepository 的注释标签下(大约在 55 行左右),添加下面这行语句以配置本地仓储位置,目录为刚刚添加的仓库文件路径
  <localRepository>C:/Application/Learn/maven-3.8.6/repository</localRepository>

在这里插入图片描述

六、 配置镜像

  1. 在 Maven 解压目录下打开 conf 目录下的 settings.xml 文件,找到 mirrors 节点(大约在 148 行左右),添加如下配置(注意要添加在 <mirrors></mirrors>两个标签之间)
<!-- 阿里云仓库 --><mirror><id>nexus-aliyun</id><name>Nexus aliyun</name><mirrorOf>central</mirrorOf><url>http://maven.aliyun.com/nexus/content/repositories/central</url></mirror><!-- 华为云仓库 --><mirror><id>huaweicloud</id><name>huaweicloud maven</name><mirrorOf>central</mirrorOf><url>https://mirrors.huaweicloud.com/repository/maven/</url></mirror><!-- 中央仓库 --><mirror><id>repo</id><name>Human Readable Name for this Mirror.</name><mirrorOf>centra</mirrorOf><url>https://repo1.maven.org/maven2/</url></mirror>

在这里插入图片描述

七、 配置JDK

  1. 在 Maven 解压目录下打开 conf 目录下的 settings.xml 文件,找到 profiles 节点(大约在 210 行左右),添加如下配置(注意要添加在 <profiles></profiles>两个标签之间)
	<!-- java版本 --> <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>

在这里插入图片描述

八、完整配置

<?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 athttp://www.apache.org/licenses/LICENSE-2.0Unless 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 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>C:/Application/Learn/maven-3.8.6/repository</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.|| Default: false<offline>false</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.|| 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.|--><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><name>Nexus aliyun</name><mirrorOf>central</mirrorOf><url>http://maven.aliyun.com/nexus/content/repositories/central</url></mirror><!-- 华为云仓库 --><mirror><id>huaweicloud</id><name>huaweicloud maven</name><mirrorOf>central</mirrorOf><url>https://mirrors.huaweicloud.com/repository/maven/</url></mirror><!-- 中央仓库 --><mirror><id>repo</id><name>Human Readable Name for this Mirror.</name><mirrorOf>centra</mirrorOf><url>https://repo1.maven.org/maven2/</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.|| 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.|| 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.|| 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.||--><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.|| 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.|| 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>--><!-- java版本 --> <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><!--<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>

九、常用命令

mvn package:打包命令,可以把项目打包成一个 jar,该命令会先执行 clean,test,compile,如果不想执行测试命令可以跳过 mvn package -Dmaven.test.skip=true

mvn compile:编译命令,可以重新编译源代码为字节码文件,如果有 jar 包没下载完成,这个命令会先把需要的 jar 包下载完成后再编译

mvn clean:清理命令,会把项目结构中的 target 文件夹中的字节码文件删除,可以组合 mvn clean compile

mvn test:测试命令会帮我们执行测试代码

mvn install:项目打包后安装到本地仓库

mvn source:jar:生成项目的源码包

mvn clean site:生成文档

十、IDEA 中配置 Maven

1. 配置当前项目

  1. 打开 IntelliJ IDEA(2023.3.6 版本),FileSettings...
    在这里插入图片描述
  2. 选择 Build, Execution, DeploymentBuild ToolsMaven,进行配置,点击 ApplyOK 即可
    在这里插入图片描述

2. 配置新建 / 新打开 项目

  1. 打 IntelliJ IDEA(2023.3.6 版本),FileNew Projects SetupSettings for New Projects...
    在这里插入图片描述
  2. 选择 Build, Execution, DeploymentBuild ToolsMaven,进行配置,点击 ApplyOK 即可
    在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/3090.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

书生·浦语大模型第二期实战营第七节-OpenCompass 大模型评测实战 笔记和作业

来源&#xff1a; 视频教程&#xff1a;https://www.bilibili.com/video/BV1Pm41127jU/?spm_id_from333.788&vd_sourcef4a51f7f5a63e756f73ad0dff318c1a3 文字教程&#xff1a;https://github.com/InternLM/Tutorial/blob/camp2/opencompass/readme.md 作业来源&#x…

【Hadoop】- MapReduce YARN 初体验[9]

目录 提交MapReduce程序至YARN运行 1、提交wordcount示例程序 1.1、先准备words.txt文件上传到hdfs&#xff0c;文件内容如下&#xff1a; 1.2、在hdfs中创建两个文件夹&#xff0c;分别为/input、/output 1.3、将创建好的words.txt文件上传到hdfs中/input 1.4、提交MapR…

HotSpot JVM 中的应用程序/动态类数据共享

0.前言 本文的目的是详细讨论 HotSpot JVM 自 JDK 1.5 以来提供的一项功能&#xff0c;该功能可以减少启动时间&#xff0c;但如果在多个 JVM 之间共享相同的类数据共享 (CDS) 存档&#xff0c;则还可以减少内存占用。 1.类数据共享 (CDS) CDS 的想法是使用特定格式将预处理…

状态模式和策略模式对比

状态模式和策略模式都是行为型设计模式&#xff0c;它们的主要目标都是将变化的行为封装起来&#xff0c;使得程序更加灵活和可维护。之所以将状态模式和策略模式进行比较&#xff0c;主要是因为两个设计模式的类图相似度较高。但是&#xff0c;从状态模式和策略模式的应用场景…

Pulsar Meetup 深圳 2024 会务介绍

“ Hi&#xff0c;各位热爱 Pulsar 的小伙伴们&#xff0c;Pulsar Meetup 深圳 2024 报名倒计时啦&#xff0c;快来报名。这里汇集了腾讯、华为和谙流科技等大量 Pulsar 大咖&#xff0c;干货多多&#xff0c;礼品多多&#xff0c;不容错过啊。 ” 活动介绍 由 AscentStream 谙…

Python 0基础_变现_38岁_day 16(文件操作)

在python&#xff0c;使用内置函数open()进行文件的一些读写操作 文件操作格式&#xff1a;open(文件路径&#xff0c;访问模式&#xff0c;字符编码) 前面两个参数是必备参数&#xff0c;后面的字符编码为选填&#xff0c;但是大多数情况下都会协商字符编码 访问模式 r 只读 w…

数码摄影色彩构成,数码相机色彩管理

一、资料描述 本套摄影色彩资料&#xff0c;大小58.54M&#xff0c;共有6个文件。 二、资料目录 《抽象彩色摄影集》.阿瑟.pdf 《色彩构成》.pdf 《色彩学》.星云.扫描版.pdf 《摄影色彩构成》.pdf 《数码相机色彩管理》.pdf 数码摄影进阶之4《色彩篇》.pdf 三、资料下…

解决IDEA中Tomcat控制台乱码问题(包括sout输出乱码)

文章目录 前言一、控制台直接输出乱码二、sout输出内容在控制台显示乱码 前言 今天在使用Tomcat的时候发现控制台输入出现了乱码问题&#xff0c;其实之前就出现过一次&#xff0c;解决了&#xff0c;但是新创建一个项目后又会出现sout的内容在控制台输出的乱码问题&#xff0…

Windows下Git的使用

目录 一、克隆远程仓库到本地二、git的三板斧2.1 add-将代码添加到本地仓库2.2 commit-提交代码到本地仓库2.3 push-推送本次添加操作到远程仓库2.4 gitee只有三板斧吗&#xff1f; 三、推送后没有出现绿点四、push到远程时报错五、git图形化界面下载链接 一、克隆远程仓库到本…

sql题目练习

cookie注入 解题思路和之前的整数型注入一样&#xff0c;只是比整数型注入多了一步&#xff0c;题目没有给输入框&#xff0c;提示“尝试找找cookie吧”cookie的中文翻译是曲奇&#xff0c;小甜饼的意思。cookie其实就是一些数据信息&#xff0c;类型为“小型文本文件”&#…

【CSS】CSS实现元素逐渐消失(实现元素透明逐渐消失/模糊)

mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%);mask-image 属性用于定义一个遮罩&#xff0c;它可以隐藏元素的一部分或全部内容。在这个示例中&#xff0c;我们使用 mask-image 属性来定义一个线性渐变的遮罩&#xff0c;使得列表项的内…

如何用微信发布考试成绩(如月考、期中、期末等)

自教育部《未成年人学校保护规定》颁布后,教育部明确表示:学校不得公开学生的考试成绩、排名等信息!同时学校应采取措施,便利家长知道学生的成绩等学业信息,对于教师来说,如何用微信发布考试成绩(如:月考、期中、期末等)就成了一道难题... 公开吧,会伤害到学生自尊心,甚至被投诉…

区块链 | OpenSea 相关论文:Toward Achieving Anonymous NFT Trading(三)

&#x1f951;原文&#xff1a; Toward Achieving Anonymous NFT Trading VII 讨论&#xff1a;关于匿名性与市场平台的困境 在本文的这一部分&#xff0c;我们将讨论关于隐藏 NFT 所有者地址的困境&#xff0c;以及为什么像 OpenSea 这样的 NFT 市场平台几乎必须得到完全的信…

企业集成平台建设方案(技术方案+功能设计)

企业集成平台建设方案及重点难点攻坚 基础支撑平台主要承担系统总体架构与各个应用子系统的交互&#xff0c;第三方系统与总体架构的交互。需要满足内部业务在该平台的基础上&#xff0c;实现平台对于子系统的可扩展性。基于以上分析对基础支撑平台&#xff0c;提出了以下要求&…

《2024年网络弹性风险指数报告》:92%的组织并未准备好应对AI安全挑战

网络弹性是一个比传统网络安全更大、更重要的范例&#xff0c;拥有有效网络弹性能力的组织能在承受网络攻击、技术故障或故意篡改企图后迅速恢复正常业务运营。近日&#xff0c;Absolute security公司发布的《2024年网络弹性风险指数报告》旨在评估当今全球企业的网络弹性状况&…

【Spring AI 来了】

spring官方已经有Spring AI 插件&#xff0c;每个程序员必定拥抱AI&#xff0c;也意味着不就以后AI的open API 会成为我们开发成的基础jdk。 下面的内容也是AI直接根据网址给我翻译的&#xff0c;连格式都是生成的。AI应用已经渗透到各行各业了&#xff0c;并且会改变我们每个…

麒麟 Kylin V10 一键安装 Oracle 11GR2 单机 ASM(231017)

前言 Oracle 一键安装脚本&#xff0c;演示麒麟 Kylin V10 一键安装 Oracle 11GR2 单机 ASM&#xff08;231017&#xff09;过程&#xff08;全程无需人工干预&#xff09;&#xff1a;&#xff08;脚本包括 ORALCE PSU/OJVM 等补丁自动安装&#xff09; ⭐️ 脚本下载地址&a…

网站网站网站

一个基于 DevUI Design 的 Vue3 组件库Home | Vue DevUI (gitee.io)https://vue-devui.gitee.io/

AI-数学-高中-42导数的概念与意义

原作者视频&#xff1a;【导数】【一数辞典】1导数的概念与意义_哔哩哔哩_bilibili .a是加速度&#xff1b;