本地仓库是远程仓库的一个缓冲和子集,当你构建Maven项目的时候,首先会从本地仓库查找资源,如果没有,那么Maven会从远程仓库下载到你本地仓库。这样在你下次使用的时候就不需要从远程下载了。如果你所需要的jar包版本在本地仓库没有,而且也不存在于远程仓库,Maven在构建的时候会报错,这种情况可能发生在有些jar包的新版本没有在Maven仓库中及时更新。
Maven缺省的本地仓库地址为${user.home}/.m2/repository 。也就是说,一个用户会对应的拥有一个本地仓库。当然你可以通过修改${user.home}/.m2/settings.xml 配置这个地址:
Xml代码
-
<settings>
-
…
-
<localRepository> D:/java/repository</localRepository>
-
…
-
</settings>
如果你想让所有的用户使用统一的配置那么你可以修改Maven主目录下的setting.xml:
${M2_HOME}/conf/setting.xml
repository是指在局域网内部搭建的repository,它跟central repository, jboss repository等的区别仅仅在于其URL是一个内部网址
mirror则相当于一个代理,它会拦截去指定的远程repository下载构件的请求,然后从自己这里找出构件回送给客户端。配置mirror的目的一般是出于网速考虑。
不过,很多internal repository搭建工具往往也提供mirror服务,比如Nexus就可以让同一个URL,既用作internal repository,又使它成为所有repository的mirror。
高级的镜像配置:
1.<mirrorOf>*</mirrorOf>
匹配所有远程仓库。 这样所有pom中定义的仓库都不生效
2.<mirrorOf>external:*</mirrorOf>
匹配所有远程仓库,使用localhost的除外,使用file://协议的除外。也就是说,匹配所有不在本机上的远程仓库。
3.<mirrorOf>repo1,repo2</mirrorOf>
匹配仓库repo1和repo2,使用逗号分隔多个远程仓库。
4.<mirrorOf>*,!repo1</miiroOf>
匹配所有远程仓库,repo1除外,使用感叹号将仓库从匹配中排除。
mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性,id是唯一标识一个mirror就不多说了,name貌似没多大用,相当于描述,url是官方的库地址,mirrorOf代表了一个镜像的替代位置,例如central就表示代替官方的中央库。
我本以为镜像库是一个分库的概念,就是说当a.jar在第一个mirror中不存在的时候,maven会去第二个mirror中查询下载。但事实却不是这样,当第一个mirror中不存在a.jar的时候,并不会去第二个mirror中查找,甚至于,maven根本不会去其他的mirror地址查询。
后来终于知道,maven的mirror是镜像,而不是“分库”,只有当前一个mirror无法连接的时候,才会去找后一个,类似于备份和容灾。
还有,mirror也不是按settings.xml中写的那样的顺序来查询的。
所谓的第一个并不一定是最上面的那个。
当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。
001 |
<? xml version = "1.0" encoding = "UTF-8" ?>
|
002 |
< settings xmlns = "http://maven.apache.org/SETTINGS/1.0.0"
|
003 |
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
|
004 |
xsi:schemaLocation = "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" >
|
005 |
006 |
< servers >
|
007 |
< server >
|
008 |
< id >repo-iss</ id >
|
009 |
< username >deployment</ username >
|
010 |
< password >deployment123</ password >
|
011 |
</ server >
|
012 |
</ servers >
|
013 |
014 |
< mirrors >
|
015 |
<!-- osc镜像 -->
|
016 |
< mirror >
|
017 |
<!-- 镜像所有远程仓库,但不包括指定的仓库 -->
|
018 |
< id >mirror-osc</ id >
|
019 |
< mirrorOf >external:*,!repo-osc-thirdparty,!repo-iss</ mirrorOf >
|
020 |
< url >http://maven.oschina.net/content/groups/public/</ url >
|
021 |
</ mirror >
|
022 |
<!-- |
023 |
<mirror>
|
024 |
<id>mirror-iss</id>
|
025 |
<mirrorOf>external:*</mirrorOf>
|
026 |
<url>http://10.24.16.99:5555/nexus/content/groups/public/</url>
|
027 |
</mirror>
|
028 |
--> |
029 |
</ mirrors >
|
030 |
031 |
< profiles >
|
032 |
< profile >
|
033 |
< id >profile-default</ id >
|
034 |
< repositories >
|
035 |
< repository >
|
036 |
< id >central</ id >
|
037 |
< url >http://central</ url >
|
038 |
< releases >
|
039 |
< enabled >true</ enabled >
|
040 |
</ releases >
|
041 |
< snapshots >
|
042 |
< enabled >false</ enabled >
|
043 |
</ snapshots >
|
044 |
</ repository >
|
045 |
< repository >
|
046 |
< id >repo-osc-thirdparty</ id >
|
047 |
< url >http://maven.oschina.net/content/repositories/thirdparty/</ url >
|
048 |
< releases >
|
049 |
< enabled >true</ enabled >
|
050 |
</ releases >
|
051 |
< snapshots >
|
052 |
< enabled >false</ enabled >
|
053 |
</ snapshots >
|
054 |
</ repository >
|
055 |
</ repositories >
|
056 |
< pluginRepositories >
|
057 |
< pluginRepository >
|
058 |
< id >central</ id >
|
059 |
< url >http://central</ url >
|
060 |
< releases >
|
061 |
< enabled >true</ enabled >
|
062 |
</ releases >
|
063 |
< snapshots >
|
064 |
< enabled >false</ enabled >
|
065 |
</ snapshots >
|
066 |
</ pluginRepository >
|
067 |
</ pluginRepositories >
|
068 |
</ profile >
|
069 |
< profile >
|
070 |
< id >profile-iss</ id >
|
071 |
< repositories >
|
072 |
< repository >
|
073 |
< id >repo-iss</ id >
|
074 |
< url >http://10.24.16.99:5555/nexus/content/groups/public/</ url >
|
075 |
< releases >
|
076 |
< enabled >true</ enabled >
|
077 |
</ releases >
|
078 |
< snapshots >
|
079 |
< enabled >true</ enabled >
|
080 |
</ snapshots >
|
081 |
</ repository >
|
082 |
</ repositories >
|
083 |
< pluginRepositories >
|
084 |
< pluginRepository >
|
085 |
< id >repo-iss</ id >
|
086 |
< url >http://10.24.16.99:5555/nexus/content/groups/public/</ url >
|
087 |
< releases >
|
088 |
< enabled >true</ enabled >
|
089 |
</ releases >
|
090 |
< snapshots >
|
091 |
< enabled >true</ enabled >
|
092 |
</ snapshots >
|
093 |
</ pluginRepository >
|
094 |
</ pluginRepositories >
|
095 |
</ profile >
|
096 |
</ profiles >
|
097 |
098 |
< activeProfiles >
|
099 |
< activeProfile >profile-default</ activeProfile >
|
100 |
<!--<activeProfile>profile-iss</activeProfile>-->
|
101 |
</ activeProfiles >
|
102 |
103 |
<!-- |
104 |
<proxies>
|
105 |
<proxy>
|
106 |
<active>true</active>
|
107 |
<protocol>http</protocol>
|
108 |
<host>10.10.204.160</host>
|
109 |
<port>80</port>
|
110 |
</proxy>
|
111 |
</proxies>
|
112 |
--> |
113 |
</ settings >
|
相关推荐
一、Idea关联的maven本地仓库配置文件settings.xml (1)必须使用默认文件名 D:\developsoft\javaweb\commonPlugins\maven\apache-maven-3.8.1_first\conf\settings.xml 二、Myeclipse关联的maven本地仓库配置文件...
maven 配置 settings.xml
Maven原版settings.xml配置文件,根据个人需要,可以打开对应注释或替换相关阿里云镜像或远程仓库地址即可使用。
maven的settings.xml配置,提供maven包下载位置,刚刚maven仓库镜像仓库下载。 <localRepository>D:/develop/apache-maven-3.6.0/repository <id>alimaven <name>aliyun maven <url>...
settings.xml maven
分享一个快的飞起的maven的settings.xml文件. 直接使用开源中国的中央仓库。
主要介绍了Maven pom.xml与settings.xml详解的相关资料,这里对pom.xml与setting.xml详细的研究说明,需要的朋友可以参考下
settings.xml配置
maven配置文件settings.xml
国内连接maven官方的仓库更新依赖,收集一些国内快速的maven仓库镜像以备用。 settings.xml配置好的国内私服,直接可以下载使用!
maven settings.xml配置文件,亲试无问题,可以使用,eclipse和Myeclipse都可以
maven 配置文件 settings.xml 支持阿里镜像下载 方便大家也方便自己
linux 环境下安装maven 拉去资源jar settings.xml 配置文件
在安装Maven构建工具后,Maven仓库镜像站点默认是国外的,因为网络原因,在构建...所以我们一定要把仓库镜像站点改为国内的才能顺利下载,通常比较常用得是阿里云镜像,已经配置好的settings.xml文件可以直接替换使用。
阿里云镜像的mavensettings.xml配置文件直接替换使用,直接替换conf/settings.xml文件就可以使用。
maven的settings.xml文件
在使用maven的时候默认缓存本地仓储到C盘,为了转移目录,我们设置settings.xml,当国外网络不理想的时候,为了快速访问国内仓储,我们设置settings.xml。此资源中包含了官方默认的,也有配置好的,及使用文档,具体...
用于maven setting.xml文件丢失,eclipse集成maven插件.m2下无setting.xml文件需要配置的情况
Maven的setting.xml下载