Adding a certificate to cacerts (java)

If you are supplied a certificate by someone and you want to insert this certificate into your cacerts file under the jdk/jre/lib/security folder then you will need to do the following:

Firstly, convert the certificate to a pem format using the openssl command:

openssl x509 -inform pem -in certfile.cer -out outfile.crt

Next import this file into your cacerts file using the keytool command:

ktool -import -alias cacert-root -file outfile.crt -keystore cacerts

Job done!