openssl x509 -in server.crt -out server.crt.der -outform der
From here the easiest thing to do is import this certificate into Java's system truststore.
keytool -keystore $JAVA_HOME/lib/security/cacerts -alias postgresql -import -file server.crt.der
If you do not have access to the system cacerts truststore you can create your own truststore.
keytool -keystore mystore -alias postgresql -import -file server.crt.der
When starting your Java application you must specify this keystore and password to use.
java -Djavax.net.ssl.trustStore=mystore -Djavax.net.ssl.trustStorePassword=mypassword com.mycompany.MyApp