如何修改仓库位置:
修改本地仓库位置使其不在c盘下(一般默认在C:\Users\Administrator\.m2\repository
)
为了使重装系统时不需要重新下载依赖包,可以将仓库设置在其它位置,方法如下:
首先,在新位置建立新文件夹当作新仓库,用来存放下载的依赖包,这里假设我新建了repos来代替原来的
repository,我的具体路径(根据自己存放位置)
:D:\Maven\repos
然后,从maven安装目录的conf下拷贝settings.xml到
D:\Maven路径下。
(这里说明下settings.xml文件里,打开后可以看到
在maven跟目录下的conf文件夹中的setting.xml
打开,找到mirrors,添加如下:
<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>
-->
这里设置了默认仓库位置为.m2/repository,也就是刚才说的c盘那个位置
)
之后,为了让它把仓库位置指向新位置,需要把conf下的settings.xml以及刚才拷贝的settings.xml里上面那段配置下新增自定义路径,以覆盖原路径
如下:
<localRepository>D:\Maven\repos</localRepository>
这样,新的仓库位置就设置好了。
这时你也可以把原来仓库
repository下的所有已下载的文件全拷贝到新仓库下
中央工厂:
在maven安装目录下的lib下找到maven-model-builder-3.3.9的jar包,解压它,可以找到pom-4.0.xml文件,打开后,可以看到其中一段代码如下:
当然,中央仓库在国外,所以下载包的速度会很慢,所以可以自己配置镜像下载地址,之前有个oschina
,不过已经挂了,最近阿里云悄悄公开了一个maven中央仓库,速度很快。配置如下:<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
url:https://repo.maven.apache.org/maven2即为中央工厂的网址,访问后可以搜查任一jar包的相关坐标信息
这是默认的中央仓库地址
或者访问:http://mvnrepository.com/
在maven跟目录下的conf文件夹中的setting.xml
打开,找到mirrors,添加如下:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>