Export the self-signed certificate from the server:
openssl s_client -connect <server>:<port> -showcerts
This will output the certificate details. Copy the section between:
-----BEGIN CERTIFICATE-----
and:
-----END CERTIFICATE-----
(including the BEGIN and END lines)
Save this block to a file, e.g. my-cert.pem
.
Then import this file to your Java Keystore:
keytool -import -trustcacerts -alias my-cert -file /path/to/my-cert.pem -keystore <JAVA_HOME>/lib/security/cacerts
Restart your Java application, now it will be able to connect to the server.
You can refer to this article for more details on this procedure: How to Import Self-Signed Certificates into Java Keystore for Local Development.