javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Sometime you might have received this kind of exception while running your application. The main reason behind this error is, the URL you are trying to access have no valid certificate issued from an authorized CA. In such cases you have to add those certificates to your JRE to make it a valid one. By using the following steps, you can make it working.
- Download security certificate from Server
- Open the URL from IE
- You will get a certificate related warning message. Click on view certificate and then Install certificate. Ignore warning messages if gets displayed.
- Now go to Tools->’Internet Options’ ->Content->Certificates.
- Locate the installed certificate from the list of certificates.
- Click “export” button and save it as “DER encoded binary” in somewhere in your PC.
- Add certificate to JRE
- Open a Command Prompt.
- Go to “bin” directory of your JRE.
- Use keytool command as follows to import the certificate to JRE.
- keytool -import -alias mycertificate -keystore ..\lib\security\cacerts -file c:\mycert.cer
- It will ask for a password. By default the password is “changeit“.
- Here I assume that your certificate is saved as “mycert.cer” in “c:\” directory.
Thats all. You have successfully added the SSL certificate to your JRE.
To confirm this use the following command.
It will display all the certificates added to the JRE cert.