本地仓库是远程仓库的一个缓冲和子集,当你构建Maven项目的时候,首先会从本地仓库查找资源,如果没有,那么Maven会从远程仓库下载到你本地仓库。这样在你下次使用的时候就不需要从远程下载了。如果你所需要的jar包版本在本地仓库没有,而且也不存在于远程仓库,Maven在构建的时候会报错,这种情况可能是有些jar包的新版本没有在Maven仓库中及时更新。 (感觉和网络里面的路由器有点像,你发请求,先在路由器缓存中找,若有就返回;没有,再去服务器下载新的再返回给用户的同时更新路由器本地缓存。)
默认仓库的存储位置
Maven缺省的本地仓库路径为${user.home}/.m2/repository
具体如下图
自定义修改仓库的存储位置:
可改变默认的 .m2 目录下的默认本地存储库文件夹
通过修改${user.home}/.m2/settings.xml 配置本地仓库路径 ,没有settings这个xml文件就新建,或者如下复制个:
模板里面的配置项都是没有修改的。就是个空白的文件,你直接修改如下图所示,就可以。简单易懂,
具体就是修改如下的Xml代码
<settings>
<localRepository>自己仓库的存放目录,我的仓库已经移动到e盘了,具体看上面的那个图的箭头所指的位置</localRepository>
</settings>
然后把Maven中央仓库换成阿里云
配置如下:
修改maven根目录下的conf文件夹中的setting.xml文件,内容如下:
< !-- 在mirrors 中配置 mirror -->
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public/
</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
本人的<mirrors>地址如下:
<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>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>maven.net.cn</id>
<name>oneof the central mirrors in china</name>
<url>http://maven.net.cn/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>