Fixing – PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

If you are trying to download Maven dependencies from Artifactory and encounter an error “PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”

It’s because JVM does not trust Artifcatory certificates. So all you need to do to fix it is to export the Artifactory certificates using browser and import it in JVM keystore executing following command after moving to $JAVA_HOME/jre/lib/security:

$ cd $JAVA_HOME/jre/lib/security

$ keytool -import -trustcacerts -alias JFrogArtifactory -file /Users/ArpitAggarwal/jfrog-artifactory.cer -keystore cacerts -storepass changeit

jfrog-artifactory.cer specified above is the artifactory certificate exported using browser.

cacerts specified above is the JVM truststore.