三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

配置maven

配置maven

配置maven

1.下载地址

Download Apache Maven – Maven

2.下载maven压缩包并解压

3.配置系统环境变量

①右键此电脑 → 属性 → 高级系统设置 →环境变量

②在系统变量(不是用户变量)点【新建】

  • 变量名:MAVEN_HOME(大写,不能写错)

  • 变量值:maven 解压根目录,例 D:\DevEnv\apache-maven-3.9.16

    ③在系统变量找到Path,编辑,新建一条:

%MAVEN_HOME%\bin

4.cmd mvn -v验证是否成功

5.修改 settings.xml(最重要,本地仓库 + 阿里云镜像,解决下载慢)

文件位置:maven解压目录/conf/settings.xml,用记事本 / VSCode 打开

ps:提前手动新建文件夹:D:\DevEnv\apache-maven-3.9.16\Repository

①设置本地仓库(不占用 C 盘)

先在 D 盘新建文件夹,例如D:\maven_repo,用来存放下载的 jar 包。

找到<settings>标签,加入下面一行(注意不要放到注释乱码):

<localRepository>D:\DevEnv\apache-maven-3.9.16\Repository</localRepository>


②添加阿里云镜像(国内下载依赖飞快)

找到文件里的<mirrors></mirrors>标签,把下面 mirror 复制粘贴进去:

aliyunmaven 阿里云公共仓库 https://maven.aliyun.com/repository/public central ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/1ff9d01d4e4c4b88ab5197bd64e41b47.png)

6.完整版

<?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. | |--><settingsxmlns="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>D:\DevEnv\apache-maven-3.9.16\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><!--阿里云镜像--><mirror><id>aliyunmaven</id><name>阿里云公共仓库</name><url>https://maven.aliyun.com/repository/public</url><mirrorOf>central</mirrorOf></mirror><!--maven3.9自带http拦截,不要删除--><mirror><id>maven-default-http-blocker</id><mirrorOf>external:http:*</mirrorOf><name>Pseudo repository to mirror external repositories initially using HTTP.</name><url>http://0.0.0.0/</url><blocked>true</blocked></mirror></mirrors><profiles><!--阿里云profile,包含仓库与插件仓库--><profile><id>aliyun</id><repositories><repository><id>aliyun-public</id><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>aliyun-plugin</id><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile></profiles><!--激活阿里云profile--><activeProfiles><activeProfile>aliyun</activeProfile></activeProfiles></settings>
← 返回列表