问题描述
我是在学习Nexus过程当中产生的该问题,然后Nexus是安装在了本地电脑。
项目报错如下:

maven配置的也没毛病呀

nexus当中也的确有该jar包呀,这就奇怪了。

问题解决
其实是配置有问题的,网上很多教程都是让你在maven当中配置<mirror>标签,实际上配置他根本就不行。在maven的setting.xml配置如下配置即可下载:
<servers>
<!-- 这是配置访问私有仓库的用户名密码 -->
<server>
<!-- id标签可以随便填,只需要在servers中唯一即可,后面很多地方会使用该id -->
<id>self-maven</id>
<username>deplyment</username>
<password>deplyment123</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<!--声明一个或多个远程仓库 -->
<repositories>
<!-- 声明一个 Nexus 私服上的仓库 -->
<repository>
<!--仓库id,这个id就是上面配置的账号密码id -->
<id>self-maven</id>
<!-- 仓库的名称 -->
<name>nexus</name>
<!--仓库的地址 -->
<url>http://localhost:8081/repository/maven-public/</url>
<!-- 是否开启该仓库的 release 版本下载支持 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 是否开启该仓库的 snapshot 版本下载支持 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 声明一个或多个远程插件仓库 -->
<pluginRepositories>
<!--声明一个 Nexus 私服上的插件仓库 -->
<pluginRepository>
<!--插件仓库 id -->
<id>self-maven</id>
<!--插件仓库 名称 -->
<name>nexus</name>
<!-- 配置的插件仓库的地址 -->
<url>http://localhost:8081/repository/maven-public/</url>
<!-- 是否开启该插件仓库的 release 版本下载支持 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 是否开启该插件仓库的 snapshot 版本下载支持 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<!-- 默认该profile生效 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
文章讲述了在学习Nexus过程中遇到的项目报错问题,即无法从Nexus下载jar包。问题出在maven配置上,不是<mirror>标签的问题,而是需要在settings.xml中配置<servers>和<profiles>,包括仓库的URL、用户名和密码,以及启用release和snapshot版本下载。通过正确配置,可以成功从私有仓库下载依赖。
3211

被折叠的 条评论
为什么被折叠?



