I used Java code to consume a website Restful API and encountered the following error:

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

Simply export the site’s certificate from your browser and dump it into your local JDK keystore.

Specific practices are as follows:

Exporting website certificate in browser:

Store in Base 64 format:



Check the location of the JRE used in Eclipse:

Go to this location and open the keystore file with Portecle:





Select Trust and import:



After successful saving, the error message disappears.

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: