1 : 仓库概念
所谓的仓库就是用于存放项目需要的jar包的。
maven采用一个仓库,多个项目的方式,让多个项目共享一个仓库里的相同jar包。
2 : 仓库默认位置
打开X:\software\apache-maven-3.5.0\conf\settings.xml
可以看到,在52行指定了仓库的位置是${user.home}/.m2/repository。
对应我的机器就是 C:\Users\X7TI.m2\repository
<?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.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.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>
-->
。。。略
3 : 默认下载路径
maven 会默认从maven官方提供的服务器下载jar包。
而官方服务器在国外,因为大家都知道的原因,网速很慢,而且容易卡断。 为了便于快速下载相关jar包,可以使用国内maven 阿里云的下载地址:使用阿里云下载路径
4 : 使用阿里云下载路径
打开x:\software\apache-maven-3.5.0\conf\settings.xml
修改在mirrors下新加一个阿里云的镜像地址:
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
也可以直接复制粘贴即可,修改位置是160-165行
5 : 修改仓库位置
仓库默认位置 是 C:\Users\X7TI.m2\repository,放在C盘有一点不好,重装系统就都没有了。所以通常我会把仓库的位置修改为:d:/maven/repository
配置文件的第55行修改即可。
使用现成的仓库
在右上角有我目前使用的maven仓库,虽不能说齐全,但是相当一部分常用的已经有了。 可以直接下载并解压在d:/maven/repository
这样就不需要自己下载了。