国内maven仓库地址 || 某个pom或者jar找不到的解决方法

解决方法

建议在maven仓库中新建settings.xml,然后把如下内容粘贴进去即可。也可以找到maven的安装目录中的conf/settings.xml,把如下的mirrors节复制到对应部分。

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <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>
</settings>

备注

linux中maven仓库默认本地路径:~/.m2/repository

windows中maven仓库本地路径:在c盘的某个.m2的文件夹下

可以用如下命令查看

如果用eclipse或者intelij的maven插件,需要从对应的ide里面的maven设置中找到maven本地仓库的路径。

引申

java项目中的pom.xml可以覆盖如上的远程仓库配置。如下实例

<repositories>
    <repository>
        <!-- Maven 自带的中央仓库使用的Id为central 如果其他的仓库声明也是用该Id
        就会覆盖中央仓库的配置 --> 
      <id>mvnrepository</id>
        <name>mvnrepository</name>
        <url>http://www.mvnrepository.com/</url>
        <layout>default</layout>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

 

posted @ 2018-03-31 21:02  海华85  阅读(9597)  评论(0编辑  收藏  举报