Maven编译打包异常解决办法之HTTPS证书问题(PKIX path building failed)

2,932 阅读1分钟

Maven编译打包异常解决办法之HTTPS证书问题(PKIX path building failed)

问题出现

在之前所有的项目都是使用的内网maven私服进行打包、编译的操作,因为内网的私服就没有启用HTTPS协议,一直使用的是HTTP协议,最近呢切换到外网使用了HTTPS协议,间歇性的就会报出错误,没法编译打包,错误信息如下:

[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolve
d: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not trans
fer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to xxxmaven (https://maven.xxx.com/repository/public): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid
er.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help1]

主要的错误信息就是这一句:

from/to xxxmaven (https://maven.xxx.com/repository/public):
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

很奇怪的是,时不时出现,就会让人很烦躁,必须根治一下。

解决方案

既然是证书的问题,那我们就需要将将对应网站的证书导入到Jdk里面去,之前采用keytool命令导入过证书,间歇性不好使(有可能是我在导出证书的时候有问题,没有去深究),下面分享一个方法,比较简单有效。

步骤:

  • 下载InstallCert.java,已经存入网盘,公众号回复【InstallCert】可以获取下载连接;

  • CMD进入到文件目录;

  • 编译InstallCert.java文件,并执行它;

    //编译Java文件
    $ javac InstallCert.java 
    //执行Java文件,并传递参数
    $ java InstallCert maven.xxx.com
    

    执行的时候,会报出上述所说的错误,并提示你输入1,输入后回车即可。执行完之后,会在当前文件夹下生成jssecacerts的文件;

  • jssecacerts文件放入JAVA_HOME/jre/lib/security目录下。

在执行maven命令就可以了,挺简单的。

有任何问题欢迎关注公众号【Hugh的白板】私信我,一起探讨,一起学习