当maven在本地找不到包的时候,就尝试从中央仓库(https://repo1.maven.org/maven2/
)获取,有的时候咱们访问外网太慢了,咱们就从镜像仓库(别的仓库或者本身的私有仓库)获取。html
<mirror> <id>tz-mirror</id> <mirrorOf>external:*,!mmkj</mirrorOf> <name>tz test nexus repository</name> <url>http://xxxxx:30003/repository/maven-proxy</url> </mirror>
id
惟一标识mirrorOf
指定镜像的规则。就是什么状况会从镜像仓库拉取,而不是从本来的仓库拉取
可选项参考连接:java
*
匹配全部external:*
除了本地缓存以后的全部仓库repo,repo1
repo
或者 repo1
。 这里repo
指的是仓库的id,下文会提到*,!repo1
除了repo1
的全部仓库name
名称描述url
地址上述的例子
除了mmkj
仓库以外,其余的全从本身的私有仓库获取(仓库我作了代理,会自动从中央仓库https://repo1.maven.org/maven2/
获取).apache
参考连接
第三方包,本身公司的包等除了手动install:install-file
导入以外,最好的办法就是搭建本身公司的私有仓库,这里推荐使用nexus, 这样除了中央仓库以外就须要设置本身的仓库了缓存
设置多仓库有2个方法:maven
<project> ... <repositories> <repository> <id>my-repo1</id> <name>your custom repo</name> <url>http://jarsm2.dyndns.dk</url> </repository> <repository> <id>my-repo2</id> <name>your custom repo</name> <url>http://jarsm2.dyndns.dk</url> </repository> </repositories> ... </project>
这里的id
就是镜像mirrorOf
使用的
${user.home}/.m2/settings.xml
)<settings> ... <profiles> ... <profile> <id>myprofile</id> <repositories> <repository> <id>my-repo2</id> <name>your custom repo</name> <url>http://jarsm2.dyndns.dk</url> </repository> ... </repositories> </profile> ... </profiles> <activeProfiles> <activeProfile>myprofile</activeProfile> </activeProfiles> ... </settings>
激活配置文件除了放在
activeProfiles
中以外,也能够使用mvn的参数
mvn -Pmyprofile ...