系統環境:
windows, Scala-2.12.10,JDK-1.8_40
錯誤提示:
Error while downloading https://repo.typesafe.com/typesafe/ivy-releases/com.lightbend/emoji_2.12/1.2.1/jars/emoji_2.12.jar:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target, ignoring it
解決步驟:
- 將錯誤提示的URL
https://repo.typesafe.com/typesafe/ivy-releases/com.lightbend/emoji_2.12/1.2.1/jars
複製到瀏覽器中訪問,右擊該網頁 進入Inspect --> Security -->View certificate -->詳細信息 -->複製到文件 來導出並保存該網站的證書。導出文件格式選擇 DER編碼二進制X.509(.CER)(D) 格式。(注:此處導出證書的步驟可能因不同瀏覽器而不同。上述步驟使用的是chrome瀏覽器。) - 用管理員權限打開命令行,運行命令
keytool -import -noprompt -trustcacerts -alias <AliasName> -file <path-to-certificate.cer> -keystore <JAVA_HOME/jre/lib/security/cacerts>
來導入證書,其中爲自定義的證書名稱,<path-to-certificate.cer>爲指向前面保存的證書文件絕對路徑,<JAVA_HOME/jre/lib/security/cacerts>爲java keystore的路徑。
- 參考[1]中的命令選項
-storepass <Password>
可以去掉,不加密碼。- 若在執行命令
keytool -list -keystore "%JAVA_HOME%/jre/lib/security/cacerts
時要輸入密碼, 其默認密碼爲changeit
除了導入證書的解決方法外,還有一種方法是使用代理proxy方式,尚未實際驗證。可參考[3, 5, 6]。
參考:
[1] Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?
[2] PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target.
[3] 關於在idea中導入sbt項目出現的問題
[4] 官方: Import the Certificate as a Trusted Certificate
[5] 使用代理的方法 scala sbt and corporate proxy - SunCertPathBuilderException
[6] SSL certificate problem in a web service proxy