如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath

时间:2024-04-03 09:34:09

今天用IDEA在打开最近在做的一个项目,想给项目添加一些别的功能,在用 maven 导入依赖的时候遇到了如下的问题:
Could not transfer artifact org.mybatis.spring.boot:mybatis-spring-boot-starter:pom:2.1.1 from/to nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public): PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
1
意思大致是在Java库中没有找到 https://maven.aliyun.com/ 的证书
下面是我的 Maven 使用的阿里云的镜像库:
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>


1.用谷歌浏览器访问 https://maven.aliyun.com/nexus/content/groups/public/
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
2.点击链接前面的小锁,然后点击如箭头所指的证书
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
3.先点击详细信息,再点击复制到文件
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
下一步
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
默认,点击下一步
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
4.把证书添加到 Java 信任证书库
把刚才下载的 ali.cer 证书放在{java安装根目录}jrelibsecurity目录下
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
在该目录下运行命令
在路径框中输入 cmd,点击回车
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
运行命令 keytool -import -alias cacerts -keystore cacerts -file ali.cer
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
输入默认密码:changeit,这是 Java 中 cacerts 证书库的默认密码
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
输入 Y,信任此证书,至此,证书导入完成
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
若提示 keytool 错误,大可不必操心,只管往下进行即可
5.重新使用 IDEA 下载 maven 依赖
如何完美解决Maven下载依赖时遇到证书问题(PKIX path building failed: sun.security.provider.certpath
就可以看到依赖在快速的下载啦~