Java:PKIX path building failed: SunCertPathBuilderException解决方法汇总

时间:2025-03-22 13:31:56

方法一

在eclipse工程上使用maven->update project时报错:

PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target

一般出现这种错误原因有以下几种

  1. maven库是https地址,本地JDK中没有这个网址的证书
  2. maven库是https地址,这个证书过期了或被更新了,但本地JDK中存的是旧证书

像我这个报错主要是因为使用的maven库是https地址:

<mirror>

    <id>......</id>

    <name>......</name>

    <url>https://XXXXX</url>

</mirror>

而这个url的证书在JDK的证书库不存在造成的

<JAVA_HOME>jre/lib/security/cacerts

因此,只需要将这个url的证书导出,再导入到cacerts中就可以了。

导入的方法可以使用命令,比如:

keytool -importcert -file -alias jetty -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit

如果本地是旧证书,则在执行上述命令前,先把旧证书删除

keytool -delete -alias jetty -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit

 执行完以上操作后,最好把PC重启一下。

方法二

在eclipse工具栏上选中“Run Configurations”,在“Maven Build”中选中需要运行的Maven项目,选中其中的“offline”选项。

其它方法可参考如下文档:

"PKIX path building failed" and "unable to find valid certification path to requested target"
/questions/21076179/pkix-path-building-failed-and-unable-to-find-valid-certification-path-to-requ

PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target
/kb/prg/java/ssl/pkix_path_building_failed/

Solve “unable to find valid certification path to requested target”
/solve-unable-to-find-valid-certification-path-to-requested-target/

【keytool】keytool查看jks证书详情
/michaelwoshi/article/details/107993556

Maven:: PKIX path building failed: : unable to find valid certification path to requested target
/wpbxin/p/

使用Maven时出现“jssecacerts PKIX path building failed: ”错
/carrie__yang/article/details/79612385