在国内访问Maven仓库,连接速度太慢。下面是将中央仓库替换成阿里云的中央仓库的方法。

第一种,统一修改仓库地址

可以直接修改Mavenconf文件夹中的setting.xml文件,或者在.m2文件夹下建立一个setting·xml文件。

setting.xml里面有个mirrors节点,用来配置镜像URL。mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性。

  • id是唯一标识一个mirror
  • name貌似没多大用,相当于描述
  • url是官方的库地址
  • mirrorOf代表了一个镜像的替代位置,例如central就表示代替官方的中央库。

mirror也不是按settings.xml中写的那样的顺序来查询的。所谓的第一个并不一定是最上面的那个。

当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。

在setting·xml中添加如下代码:

  1. <mirrors>
  2. ...
  3. <mirror>
  4. <id>alimaven</id>
  5. <name>aliyun maven</name>
  6. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  7. <mirrorOf>central</mirrorOf>
  8. </mirror>
  9. </mirrors>

第二种,分别给每个项目配置不同的中央库
直接在项目的pom.xml中修改中央库的地址。如下:

  1. <repositories>
  2. <repository>
  3. <id>alimaven</id>
  4. <name>aliyun maven</name>
  5. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  6. </repository>
  7. </repositories>

完整的pom:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.xiaolyuh</groupId>
  5. <artifactId>spring-boot-student</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <packaging>pom</packaging>
  8. <name>spring-boot-student</name>
  9.  
  10. <!-- 添加Spring Boot的父类依赖,这样当前项目就是Spring Boot项目了。 spring-boot-starter-parent是一个特殊的starter,他用来
  11. 提供相关的maven默认依赖, 使用它之后,常用的依赖可以省去version标签 -->
  12. <parent>
  13. <groupId>org.springframework.boot</groupId>
  14. <artifactId>spring-boot-starter-parent</artifactId>
  15. <version>1.5.3.RELEASE</version>
  16. <relativePath /> <!-- lookup parent from repository -->
  17. </parent>
  18.  
  19. <repositories>
  20. <repository>
  21. <id>alimaven</id>
  22. <name>aliyun maven</name>
  23. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  24. </repository>
  25. </repositories>
  26.  
  27. <!-- 或者在maven的setting文件中加入 -->
  28. <!--<mirror>
  29. <id>alimaven</id>
  30. <name>aliyun maven</name>
  31. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  32. <mirrorOf>central</mirrorOf>
  33. </mirror>-->
  34.  
  35. <properties>
  36. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  37. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  38. <java.version>1.8</java.version>
  39. </properties>
  40.  
  41. <dependencies>
  42. <dependency>
  43. <groupId>org.springframework.boot</groupId>
  44. <artifactId>spring-boot-starter</artifactId>
  45. </dependency>
  46.  
  47. <dependency>
  48. <groupId>org.springframework.boot</groupId>
  49. <artifactId>spring-boot-starter-test</artifactId>
  50. <scope>test</scope>
  51. </dependency>
  52. </dependencies>
  53.  
  54. <build>
  55. <plugins>
  56. <plugin>
  57. <groupId>org.springframework.boot</groupId>
  58. <artifactId>spring-boot-maven-plugin</artifactId>
  59. </plugin>
  60. </plugins>
  61. </build>
  62.  
  63. </project>

这个就是原生的Sonattype Nexus.... 其实阿里很多做过类似的事情,阿里的开源软件的Mirrors,阿里的Ruby语言的gem和NodeJs的npm仓库。作为一个Linux用户,我一直用的阿里的mirror,速度很快。现在阿里开放了 maven仓库,是件好事,造福很多Java程序员。

现在很多大佬都在稍稍的布局,阿里的maven更是如此,因为有了阿里的maven,我才知道阿里的git,有了阿里的maven,我才知道阿里的持续交付,有了阿里的maven,我才向老板推荐了阿里云服务器,现在公司第年在阿里云上大概消耗3000元的样子。

https://www.zhihu.com/question/49097325

archetypeCatalog用来指定maven-archetype-plugin读取archetype-catalog.xml文件的位置:

internal——maven-archetype-plugin内置的
local——本地的,位置为~/.m2/archetype-catalog.xml
remote——指向Maven中央仓库的Catalog
修改阿里云镜像后,若不能使用命令’mvn archetype:generate -DarchetypeCatalog=local’
$ cp ~/.m2/archetype-catalog.xml ~/.m2/repository/
https://blog.csdn.net/tengxing007/article/details/72588242

Webmin管理工具
目前功能最强大的基于Web的Linux系统管理工具,Webmin让您能够远程通过Web界面管理您的主机

https://market.aliyun.com/spec/panel?utm_content=se_1000089576

https://blog.csdn.net/tengxing007/article/details/72588242

internal repository是指在局域网内部搭建的repository,它跟central repository, jboss repository等的区别仅仅在于其URL是一个内部网址
mirror则相当于一个代理,它会拦截去指定的远程repository下载构件的请求,然后从自己这里找出构件回送给客户端。
配置mirror的目的一般是出于网速考虑。

可以看出,internal repository和mirror是两码事。
前者本身是一个repository,可以和其它repository一起提供服务,比如它可以用来提供公司内部的maven构件;
而后者本身并不是repository,它只是远程repository的网络加速器

不过,很多internal repository搭建工具往往也提供mirror服务,比如Nexus就可以让同一个URL,既用作internal repository,又使它成为所有repository的mirror。

如果仓库X可以提供仓库Y存储的所有内容,那么就可以认为X是Y的一个镜像。换句话说,任何一个可以从仓库Y获得的构件,都胡够从它的镜像中获取。
举个例子,http://maven.net.cn/content/groups/public/ 是中央仓库http://repo1.maven.org/maven2/ 在中国的镜像,由于地理位置的因素,该镜像往往能够提供比中央仓库更快的服务。
因此,可以配置Maven使用该镜像来替代中央仓库。
settings.xml

  1. <settings>
  2. ...
  3. <mirrors>
  4. <mirror>
  5. <id>maven.net.cn</id>
  6. <name>one of the central mirrors in china</name>
  7. <url>http://maven.net.cn/content/groups/public/</url>
  8. <mirrorOf>central</mirrorOf>
  9. </mirror>
  10. </mirrors>
  11. ...
  12. </settings>

https://blog.csdn.net/caomiao2006/article/details/40401517

一些其它的maven中央仓库

  1. <mirror>
  2. <id>alimaven</id>
  3. <name>aliyun maven</name>
  4. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  5. <mirrorOf>central</mirrorOf>
  6. </mirror>
  7. <mirror>
  8. <id>central</id>
  9. <name>Maven Repository Switchboard</name>
  10. <url>http://repo1.maven.org/maven2/</url>
  11. <mirrorOf>central</mirrorOf>
  12. </mirror>
  13. <mirror>
  14. <id>repo2</id>
  15. <mirrorOf>central</mirrorOf>
  16. <name>Human Readable Name for this Mirror.</name>
  17. <url>http://repo2.maven.org/maven2/</url>
  18. </mirror>
  19. <mirror>
  20. <id>ibiblio</id>
  21. <mirrorOf>central</mirrorOf>
  22. <name>Human Readable Name for this Mirror.</name>
  23. <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
  24. </mirror>
  25. <mirror>
  26. <id>jboss-public-repository-group</id>
  27. <mirrorOf>central</mirrorOf>
  28. <name>JBoss Public Repository Group</name>
  29. <url>http://repository.jboss.org/nexus/content/groups/public</url>
  30. </mirror>
  31. <!-- 中央仓库在中国的镜像 -->
  32. <mirror>
  33. <id>maven.net.cn</id>
  34. <name>oneof the central mirrors in china</name>
  35. <url>http://maven.net.cn/content/groups/public/</url>
  36. <mirrorOf>central</mirrorOf>
  37. </mirror>

阿里maven仓库地址的更多相关文章

  1. PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilder,阿里MAVEN仓库地址更新为了https问题

    http://maven.aliyun.com/nexus/content/groups/public/,仓库地址更新为了https,所以下载时需要ssl认证,我们可以忽略ssl检查导致的问题,我们可 ...

  2. 阿里maven仓库地址 和 oschina maven仓库地址

    <mirror>     <id>nexus-aliyun</id>     <mirrorOf>*</mirrorOf>     < ...

  3. maven 动态版本 aliyun阿里云Maven仓库地址——加速你的maven构建

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. 国内maven仓库地址资源汇总

    国内maven仓库地址:阿里云maven仓库,网易163maven仓库,以及其他maven仓库地址. 国内下载maven一般速度都很慢,下载需要很久时间.这里汇总了一些国内的镜像资源 附带pom文件中 ...

  5. maven 仓库地址:

    maven 仓库地址: 共有的仓库 http://repo1.maven.org/maven2/http://repository.jboss.com/maven2/ http://repositor ...

  6. 收集的maven 仓库地址(maven repository)

    maven 仓库地址: 共有的仓库http://repo1.maven.org/maven2/http://repository.jboss.com/maven2/http://repository. ...

  7. Gradle 修改 Maven 仓库地址

    gradle install--- http://www.itnose.net/detail/6500082.html http://stackoverflow.com/questions/51025 ...

  8. 国内阿里Maven仓库镜像及自己收集镜像库

    国内阿里Maven仓库镜像Maven配置文件Maven仓库速度快   国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用. 最新更新:2016年11月11 ...

  9. Gradle修改缓存路径 和 Gradle修改Maven仓库地址

    Gradle修改缓存路径 修改gradle启动脚本进入gradle安装的bin目录,使用文本编辑器打开gradle.bat文件,在如图的位置添加以下语句 set GRADLE_OPTS="- ...

随机推荐

  1. Java静态分派与动态分派(二)

    方法调用并不等于方法执行,方法调用阶段唯一的任务就是确定被调用方法的版本(即调用哪一个方法),暂时还不涉及方法内部的具体运行过程. 在程序运行时,进行方法调用是最普遍.最频繁的操作,但是Class文件 ...

  2. linux系列之-—03 常见问题

    问题1 描述:Linux如何查看JDK的安装路径 问题2 描述:执行shell脚本时报错,错误信息为:bash: line 19: jar: command not found 原因:因为在系统环境变 ...

  3. How to get service execuable path

    Some time we need to get specific service path and then do something you want. there are 2 way to ge ...

  4. OpenGL的版本号历史和发展

    来源请注明.本文永久地址为http://www.cnblogs.com/vertexshader/articles/2917540.html OpenGL®作为业界最为广泛使用的2D和3D图形接口标准 ...

  5. jQuery的AJax异步訪问

    用一个样例用以说明:点击button,将input内用户输入的数据发送给服务端.并将结果返回给页面. 首先是html承载内容: <!DOCTYPE html> <html> & ...

  6. 2016/3/24 ①数据库与php连接 三种输出fetch_row()、fetch_all()、fetch_assoc() ②增删改时判断(布尔型) ③表与表之间的联动 ④下拉菜单 ⑤登陆 三个页面

    ①数据库与php连接   图表 header("content-type:text/html;charset=utf-8"); //第一种方式: //1,生成连接,连接到数据库上的 ...

  7. css的白富美

    1,CSS(Cascading Style Sheet)是用来装饰HTML的,当浏览器读到这样一个样式的时候,它就会按照这个文档进行格式化(渲染) 2,CSS的组成:选择器和声明,声明又包括属性和属性 ...

  8. SSH三大框架整合配置详细步骤(2)

    4 配置Hibernate Hibernate MySql连接配置 在Hibernate中,可以配置很多种数据库,例如MySql.Sql Server和Oracle,Hibernate MySql连接 ...

  9. 高负载linux调优

    调整Linux内核参数: # vi /etc/sysctl.conf# tells the Kernel it's ok if services bind to non-existant IP ADD ...

  10. centos7和redhat7的比特币环境搭建

    比特币版本是 bitcoin-0.12 问题1: [root@localhost bitcoin-master]# ./autogen.sh  which: no autoreconf in (/us ...