开发者社区 问答 正文

idea使用maven构建服务,报PKIX path building failed错误

环境:     电脑型号:ThinkPad R480 16G+500G Windows10系统     IDE工具:IntelliJ IDEA 2018.1.5     Java版本:jdk1.8.0_171     Maven版本:apache-maven-3.6.2

问题描述:     设置好Java和Maven环境后,使用idea中的spring initializr构建一个只包含web的demo,下载依赖时出现以下错误:

D:\Java\jdk1.8.0_171\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\demo -Dmaven.home=D:\apache-maven-3.6.2 -Dclassworlds.conf=D:\apache-maven-3.6.2\bin\m2.conf "-javaagent:D:\IntelliJ IDEA 2018.1.5\lib\idea_rt.jar=60044:D:\IntelliJ IDEA 2018.1.5\bin" -Dfile.encoding=UTF-8 -classpath D:\apache-maven-3.6.2\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version=2018.1.5 clean -f pom.xml
[INFO] Scanning for projects...
Downloading from nexus-aliyun: https://maven.aliyun.com/repository/public/org/springframework/boot/spring-boot-starter-parent/2.2.2.RELEASE/spring-boot-starter-parent-2.2.2.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.2.RELEASE from/to nexus-aliyun (https://maven.aliyun.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 and 'parent.relativePath' points at no local POM @ line 5, column 13
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.example:demo:0.0.1-SNAPSHOT (D:\IdeaProjects\demo\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.2.RELEASE from/to nexus-aliyun (https://maven.aliyun.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 and 'parent.relativePath' points at no local POM @ line 5, column 13 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

Process finished with exit code 1

settings文件配置如下:

<?xml version="1.0" encoding="UTF-8" ?>
 
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>D:\repository</localRepository>
    <pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>
    <servers>
    </servers>
    <mirrors>
        <mirror>
			<id>nexus-aliyun</id>
			<mirrorOf>*</mirrorOf>
			<name>Nexus aliyun</name>
			<url>https://maven.aliyun.com/repository/public</url>
        </mirror>
        <mirror>
            <id>central</id>
			<mirrorOf>*</mirrorOf>
            <name>Maven Repository Switchboard</name>
            <url>https://repo1.maven.org/maven2/</url>
        </mirror>
    </mirrors>
    <profiles>
    </profiles>
</settings>
 

百度出的结果是需要信任阿里证书,已添加信任

图片.png

甚至生成了jssecacerts文件,修改过maven版本,都没有作用,求大神指教!

展开
收起
游客w7odq4xhefpvk 2019-12-16 17:31:26 3118 分享 版权
阿里云 AI 助理回答

遇到这个问题,通常是因为Maven在尝试从远程仓库下载依赖时,遇到了SSL证书验证的问题。尽管你已经尝试了添加信任证书,但问题仍然存在,这可能是因为Java的JDK信任库没有正确更新或识别你的证书。以下是一些解决步骤,你可以尝试:

  1. 确认证书已正确导入: 确保jssecacerts文件中确实包含了阿里云仓库的证书,并且该文件位于正确的路径下(通常是%JAVA_HOME%\jre\lib\security%JAVA_HOME%\lib\security)。如果直接修改了cacerts文件,请确保备份原始文件。

  2. 使用keytool命令检查和添加证书: 使用Java的keytool工具手动检查和添加证书到信任库。首先,你需要导出阿里云仓库的证书到本地,然后用下面的命令将其导入到Java的信任库中:

    keytool -importcert -file path_to_your_certificate.crt -alias aliyunmaven -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -storepass changeit
    

    这里path_to_your_certificate.crt是阿里云仓库证书的路径,-alias可以自定义,-storepass是默认密码(除非你之前更改过)。

  3. 重启IDEA: 修改完信任库后,需要完全关闭并重新启动IntelliJ IDEA,以确保它使用的是更新后的证书信息。

  4. 检查网络代理设置: 如果你处于公司内网或者使用了代理服务器,可能需要在Maven的settings.xml中配置代理设置,确保Maven能够通过代理访问外部资源。

  5. 直接使用http而非https: 作为临时解决方案,可以在Maven的settings.xml中将阿里云仓库的URL由https改为http,但这不是最安全的做法,因为不加密的数据传输可能会有安全风险。

    <repository>
       <id>nexus-aliyun</id>
       <url>http://maven.aliyun.com/nexus/content/groups/public</url>
       <name>Nexus aliyun</name>
    </repository>
    
  6. 检查系统时间: 确保你的系统时间是准确的,错误的系统时间也可能导致SSL握手失败。

如果以上方法都不能解决问题,建议彻底卸载重装JDK,并在安装过程中确保所有安全相关的选项都保持默认,然后再重复上述步骤。希望这些建议能帮助你解决问题。

有帮助
无帮助
AI 助理回答生成答案可能存在不准确,仅供参考
0 条回答
写回答
取消 提交回答