阿里巴巴私服nexus使用

刚学maven不久,今天在搭建maven项目的时候,碰到了好多jar包下载错误的问题,后来配置了maven私服仓库,成功的解决了问题。原因是maven从自己默认提供的中央仓库中下载时部分jar包因为未知原因无法下载。所以从第三方仓库(阿里巴巴私服nexus)下载是一个很好的选择。

1、在maven安装目录下conf里面的setting.xml(配置文件里面添加一段代码)

<mirrors>
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
  </mirrors>
注意:因为原文件中有一个空的<mirrors></mirrors>标签,所以直接添加会出现重复标签错误,所以要先找的原来的标签加以修改即可。

2、在maven工程的pom.xml文件中加入如下代码:

 <repositories>
        <repository>
            <id>nexus-aliyun</id>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus-aliyun</id>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

完成后重新build项目,即可下载所有的jar包。若有其他错误,另寻解决方法。

猜你喜欢

转载自blog.csdn.net/qq_40692753/article/details/83062566