一、背景
maven编译时遇到如下情况,其他同事没有遇到过,根据 “PKIX path building failed:” 这个去搜发现可能是因为缺少证书。
Downloading: http://edas-public.oss-cn-hangzhou.aliyuncs.com/repository/org/springframework/boot/spring-boot-maven-plugin/1.5.6.RELEASE/spring-boot-maven-plugin-1.5.6.RELEASE.pom
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/1.5.6.RELEASE/spring-boot-maven-plugin-1.5.6.RELEASE.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.430 s
[INFO] Finished at: 2019-10-28T16:35:22+08:00
[INFO] Final Memory: 13M/245M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "downloadSources" could not be activated because it does not exist.
[ERROR] Plugin org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.springframework.boot:spring-boot-maven-plugin:jar:1.5.6.RELEASE: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:1.5.6.RELEASE from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
二、解决方案
可以从报错信息看出,不能从 https://repo.maven.apache.org/maven2 仓库中下载 spring-boot-maven-plugin1.5.6;按照如下步骤解决:
- 用浏览器(谷歌 77.0.3865.120版本)打开仓库,我这儿是 https://repo.maven.apache.org/maven2 ;可以看见的网址上左上角一个加锁的标志,点击;
2.点击证书标志,选择详细信息,一路下一步,直到另外保存证书到指定目录,可以直接放在jdk安装目录下的jre\lib\security下( $JAVA_HOME/jre/lib/securiy);我这儿取名为repo.maven.apache.org;
3.执行命令导入证书;Java 使用了一种叫 keystore 的文件来存储证书 ,默认是位于 "$JAVA_HOME/lib/security/cacerts" ;执行cmd,找到
D:\BianCheng\jdk\path\jdk1.8\jre\bin\keytool.exe -import -v -trustcacerts -alias maven -file D:/BianCheng/jdk/maven.cer -storepass changeit -keystore D:/BianCheng/jdk/path/jre/lib/security
4.其他参考地址
JAVA 导入信任证书 (Keytool 的使用)
网友评论