How to import valid certificates to java key store file.

How to import valid certificates to java key store file.

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

Solution:

1. Get the SSL certificate from your IT team.

To import this certificate on JAVA, please follow below steps

2.Open the CMD and go to you JDK/bin path, like C:\Program Files\Java\jdk1.8.0_91\bin

3.keytool -importcert -file "D:\SSL-Certificate\filename.cer" -alias randomaliasname -keystore  JAVA_HOME/jre/lib/security/cacerts -storepass changeit
 
If above command not executed successfully, then use the below command. ie., enter full path of JAVA_HOME path as shown in below example.
Example: keytool -importcert -file "C:\Program Files\Java\jre1.8.0_201\bin\root_aeserver.cer" -alias root -keystore  "C:\Program Files\Java\jdk1.8.0_201\jre\lib\security\cacerts" -storepass changeit
Example: keytool -importcert -file "C:\Program Files\Java\jre1.8.0_201\bin\Intermediate_aeserver.cer" -alias intermediate -keystore  "C:\Program Files\Java\jdk1.8.0_201\jre\lib\security\cacerts" -storepass changeit
Example: keytool -importcert -file "C:\Program Files\Java\jre1.8.0_201\bin\Primary_aeserver.cer" -alias primary -keystore  "C:\Program Files\Java\jdk1.8.0_201\jre\lib\security\cacerts" -storepass changeit

(Note: Client can provide only two certificates as well)
4.Now apply the same certificate on JRE folder as well.

keytool -importcert -file "D:\SSL-Certificate\filename.cer" -alias randomaliasname -keystore  JRE_HOME/lib/security/cacerts -storepass changeit
If above command not executed successfully, then use the below command. ie., enter full path of JRE_HOME path
keytool -importcert -file "C:\Program Files\Java\jre1.8.0_201\bin\root_aeserver.cer" -alias root -keystore  "C:\Program Files\Java\jre1.8.0_201\lib\security\cacerts" -storepass changeit
keytool -importcert -file "C:\Program Files\Java\jre1.8.0_201\bin\Intermediate_aeserver.cer" -alias intermediate -keystore  "C:\Program Files\Java\jre1.8.0_201\lib\security\cacerts" -storepass changeit
keytool -importcert -file "C:\Program Files\Java\jre1.8.0_201\bin\Primary_aeserver.cer" -alias primary -keystore  "C:\Program Files\Java\jre1.8.0_201\lib\security\cacerts" -storepass changeit
           
5.Verify whether installed certificates are available or not.
keytool -list -keystore "C:\Program Files\Java\jre1.8.0_201\lib\security\cacerts"

6.Restart the server.

      Links to better reach 

            Bot Store

             EPD