Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

💥 ERROR1: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

This occurs when Java doesn’t trust the SSL certificate of the site/server you're connecting to.

...

Solution

Step 1: Export the Certificate

  • Export the certificate from your browser or download it from a trusted source.

  • Save it as:
    C:\Users\Administrator\Downloads\emSign Root CA - G1.crt

...

Step 2: Navigate to Java Security Folder

Open PowerShell as Administrator and run:

cd 'C:\Program Files\Java\jdk-17.0.3.1\lib\security' 

...

Step 3: Import the Certificate into Java Truststore

Run the following command in the same PowerShell window:

keytool -importcert -file 'C:\Users\Administrator\Downloads\emSign Root CA - G1.crt' -keystore .\cacerts -alias 'cn_emsign_root_ca__g1,o_emudhra_technologies_limited,ou_emsign_pki,c_in [jdk]' 

When prompted for a password, enter: changeit

✅ Confirm the import by typing yes when prompted.

...

🔄 Step 4: Restart Java-Based Application

Restart the Java application

...

— it should now trust the certificate.