This has been here a lot.
If your server certificate is not in global trustchain for example self generated, you need to get servers certificate and add it to clients keystore. Keystore can be used in basic level like this:
String keystorePath = "local.keystore";
System.setProperty("javax.net.ssl.trustStore", keystorePath);
Please use search to get specific explanations on topic.
If you have direct access to server from webbrowser you can use it to save certificate, but if you can use Linux command-line then this link may be of help.
To add new certs into keystore, you can use Java keytool
command. There are also lots of examples you can Google yourself about Java keystores.