Import SSL Certificate into Java keystore

Import SSL Certificate into Java keystore

We will get the error when we try to access HTTPS urls in java. To avoid these certificate issues, we need to import the SSL Certificate into JVM

Caused by: PKIX path building failed: unable to find valid certification path to requested target


  1. Download the Certificate
  2. Import the Certificate into JVM using keytool


  • Download the certificate:


  1. Open the URL in chrome browser:
  2. Press F12 to access developer tools
  3. Go to security tab
  4. Click on View certificate and click on Details tab in the following window.
  5. Click on “Copy to File”  and again click on “Next button”
  6. Specify the file name by clicking on “Browse” button.
  7. Now click on finish



Step2: Import the SSL Certificate

JDK provides keytool to import the SSL Certificate

  1. Open CMD prompt in admin mode and enter “keytool -importcert -help”

    Java Keytool
    Java Keytool
  2. In the above steps, i downloaded the certificate into  C:\Users\pokurija\Pictures\javasavvy\gradle.cer path
  3. Navigate to “C:\Program Files\Java\jre\lib\security” path and give the following command to import the cert.
    • C:\Program Files\Java\jre\lib\security>keytool -importcert -trustcacerts -file C:\Users\jai\Pictures\javasavvy\gradle.cer -keystore cacerts -alias "gradle"
    • It will prompt for keystore password and enter  “changeit” for both times. chnageit is default password for cacerts, so do no change this. Java SSL Certificate Installation

Hope this helps.

4 thoughts on “Import SSL Certificate into Java keystore”

Leave a Reply

Your email address will not be published. Required fields are marked *