Java SSLException "PKIX path building failed: unable to find valid certification path to requested target" — Java cannot build the trust chain. JVM truststore ($JAVA_HOME/lib/security/cacerts) lacks the server's CA or intermediate. Fixes: (1) keytool -import into cacerts, (2) -Djavax.net.ssl.trustStore for an alternate truststore, (3) -Djavax.net.debug=ssl,handshake for diagnostics.
Below: details, example, related, FAQ.
Free online tool — SSL certificate checker: instant results, no signup.
# Download CA cert from server
$ echo | openssl s_client -connect server:443 -showcerts 2>/dev/null | \
openssl x509 -out server-ca.crt
# Import into Java cacerts
$ sudo /bin/keytool -import \
-alias server-ca \
-keystore /lib/security/cacerts \
-storepass changeit \
-file server-ca.crt
# Debug app
$ java -Djavax.net.debug=ssl:handshake MyAppThe PKIX path building process is crucial for establishing a secure SSL/TLS connection. This process involves constructing a chain of trust from the server's SSL certificate to a trusted root certificate stored in the Java truststore. Here’s how it works:
When a Java application attempts to establish an SSL connection, it first receives the server's certificate. The Java Virtual Machine (JVM) then checks if this certificate can be validated against the certificates in its truststore. If the server's certificate is issued by a Certificate Authority (CA) that is not in the truststore, the validation fails, resulting in the sun.security.validator.ValidatorException: PKIX path building failed error.
This process consists of several steps:
If any certificate in the chain is missing or untrusted, the PKIX path building will fail. To resolve this, ensure that all necessary CA and intermediate certificates are imported into the JVM's truststore.
Understanding the common causes of PKIX path building failed errors can help you troubleshoot SSL issues effectively. Here are the primary reasons:
-Djavax.net.ssl.trustStore option is correct and accessible.To prevent these issues, always verify the truststore contents and ensure that the necessary certificates are present. Using tools like keytool can help you manage and inspect your truststore efficiently.
Resolving the PKIX path building failed error can often be accomplished with a few simple commands. Below are practical examples that demonstrate how to import certificates and configure the JVM:
To import a server's certificate into the default JVM truststore, use the following command:
keytool -import -alias myserver -file server.crt -keystore $JAVA_HOME/lib/security/cacertsWhen prompted, enter the truststore password, which is typically changeit.
If you prefer to use a custom truststore, you can specify its path when starting your Java application:
java -Djavax.net.ssl.trustStore=/path/to/custom.truststore -Djavax.net.ssl.trustStorePassword=yourpassword -jar yourapp.jarTo gain insights into the SSL handshake process and diagnose issues, enable SSL debugging by adding the following option:
-Djavax.net.debug=ssl,handshakeThis will provide detailed logs of the SSL connection attempts, helping you identify where the PKIX path building is failing.
Using these commands, you can effectively manage your truststore and troubleshoot SSL connection issues related to PKIX path building.
SSL/TLS is the encryption protocol that protects data between the browser and server. Our tool analyzes the certificate, chain of trust, TLS version, and knownvulnerabilities.
Issuer, validity period, signature algorithm, covered domains (SAN), and validation type (DV/OV/EV).
Full chain verification: from leaf certificate through intermediates to root CA.
Protocol version (TLS 1.2/1.3), cipher suites, Perfect Forward Secrecy (PFS) support.
Set up a monitor — get Telegram and email alerts 30/14/7 days before expiration.
SSL certificate monitoring
TLS config audit
HTTPS as ranking factor
customer trust
www and subdomains.Strict-Transport-Security header forces browsers to always use HTTPS.SSL certificate monitoring, check history and alerts 30 days before expiry.
Sign up freeCopy into an app-specific jks + -Djavax.net.ssl.trustStore. JDK updates won't reset it.
For dev: a TrustManager that accepts everything. Never ship that in prod code.
-Djavax.net.ssl.trustStore in MAVEN_OPTS / GRADLE_OPTS, or <jvmArgs> in the build files.
Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.