Maven错误,PKIX路径构建失败:无法找到请求目标的有效证书路径

时间:2017-08-10 11:43:41

标签: java maven

有两个远程服务器存在。假设我们将它们命名为A和B. 我的Java代码已在GIT存储库上提交并保持最新。 我在服务器A和B上都删除了代码。当我在服务器A上使用mvn clean package install时,它正常工作并且构建成功完成。 但是当我为服务器B使用mvn clean package安装时,它会给我带来构建失败按摩的错误。

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] oagi-srt ........................................... SUCCESS [  0.292 s]
[INFO] oagi-srt-common .................................... SUCCESS [  1.959 s]
[INFO] oagi-srt-repository ................................ SUCCESS [  2.357 s]
[INFO] oagi-srt-service ................................... SUCCESS [  2.064 s]
[INFO] oagi-srt-import .................................... SUCCESS [  3.064 s]
[INFO] oagi-srt-webapp .................................... FAILURE [ 21.398 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 31.539 s
[INFO] Finished at: 2017-08-10T11:50:10+00:00
[INFO] Final Memory: 44M/303M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project srt-webapp: Could not resolve dependencies for project org.oagi:srt-webapp:war:1.0.0: Failed to collect dependencies at org.joinfaces:jsf-spring-boot-starter:jar:2.2.7 -> org.primefaces.extensions:all-themes:jar:1.0.8 -> org.primefaces.themes:afterdark:jar:1.0.8: Failed to read artifact descriptor for org.primefaces.themes:afterdark:jar:1.0.8: Could not transfer artifact org.primefaces.themes:themes-project:pom:1.0.8 from/to prime-repo-new (http://repository.primefaces.org): 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/DependencyResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :srt-webapp

注意: - 如果我直接将项目 war文件放在tomcat中并重新启动服务器,我的应用程序正如我在两台服务器上所期望的那样正常工作。

6 个答案:

答案 0 :(得分:6)

我的公司IT策略阻止了Maven Repo https,因为证书的到期日期很短。 导入证书很麻烦。所以我用这种方法来解决它:

  • 更改为最新版本(已在3.6.3版上验证)
  • 添加这些参数
mvn clean package -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true

答案 1 :(得分:1)

您的B服务器似乎没有访问存储库的证书,尝试比较服务器A和B之间的环境证书。

另请查看此问题:How do I find out what keystore my JVM is using?

答案 2 :(得分:1)

我在运行mvn clean install时遇到了相同的错误,而对我来说解决方案却大不相同...

我在Maven的settings.xml文件中有一个代理条目,例如:

<proxies>
  <proxy>
    ... 
  </proxy>
</proxies>

我尝试将证书导入到我的cacert和所有证书中,但是这些都无济于事。

仅在删除上述代理条目后,它才起作用。 (可能是我们公司的代理服务器设置发生了变化,因此我从前获得的上述设置无效)

答案 3 :(得分:0)

如果您使用的是apache maven存储库以外的存储库,请尝试在网址中使用http而不是https

答案 4 :(得分:0)

我知道线程很旧。也许这是给其他可能偶然发现此问题的用户的答案

EM-Creations是正确的。使用http将导致默认重定向到https。我搜索了几个stackoverflow问题和其他站点,正确的答案将是使Maven信任我们要使用的存储库/ URL /站点的证书

首先,我们需要导入该零件站点的(根)证书。请点击此链接 https://www.comodo.com/support/products/authentication_certs/setup/mac_chrome.php

现在,maven默认使用Java密钥库可信证书,并且默认情况下可信证书位于{JAVA_HOME}/jre/lib.security/cacerts。因此,下一步是将我们下载的证书添加到cacerts。为此,您可以使用openssl或keytool命令。我个人更喜欢keytool,这是一个示例

keytool 
-import 
-storepass <STOREPASS_PASSWORD> 
-noprompt 
-alias < unique  certificate alias for Keystore> 
-keystore <JRE_HOME>/lib/security/cacerts 
-trustcacerts 
-file <certificate file>

对于mac用户,默认执行将导致权限被拒绝错误。因此,您可以使用sudo使其可执行且可写

答案 5 :(得分:0)

当我的JRE没有正确的证书来通过公司代理并回购到仓库时,我会遇到此问题。

步骤1 将取决于您的IT部门。您需要找到使您可以通过https代理进行访问的 .crt 文件,并将其下载为Your_Proxy.crt

第2步正在运行“ mvn -version”,以确保您100%知道您的maven正在使用哪个JRE。

第3步将使用Windows上的Powershell或linux上的sudo在管理员模式下转到JRE文件夹。

./bin/keytool.exe -importcert -ckeystore cacerts -file Your_Proxy.crt -alias Add_name_here

...您将需要知道密钥库的密码,该密码通常默认为“ changeit”