阿里maven仓库地址

在国内访问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中添加如下代码:

<mirrors>  
    ...   
    <mirror>  
      <id>alimaven</id>  
      <name>aliyun maven</name>  
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf>          
    </mirror>
</mirrors>

 




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

<repositories>
    <repository>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </repository>
</repositories>

完整的pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xiaolyuh</groupId>
    <artifactId>spring-boot-student</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>spring-boot-student</name>

    <!-- 添加Spring Boot的父类依赖,这样当前项目就是Spring Boot项目了。 spring-boot-starter-parent是一个特殊的starter,他用来 
        提供相关的maven默认依赖, 使用它之后,常用的依赖可以省去version标签 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <repositories>
        <repository>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        </repository>
    </repositories>

    <!-- 或者在maven的setting文件中加入 -->
    <!--<mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>-->

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</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

<settings>
  ...
  <mirrors>
    <mirror>
      <id>maven.net.cn</id>
      <name>one of the central mirrors in china</name>
      <url>http://maven.net.cn/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

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

 

一些其它的maven中央仓库

<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>

 

posted @ 2018-04-06 20:24  沧海一滴  阅读(2325)  评论(0编辑  收藏  举报