Java Keystore Import Error

When trying I started recieveing the following error:

keytool error: java.lang.Exception: Input not an X.509 certificate

My certificate was in the .pem format and all that I had to do was convert the certificate using the following command:

openssl x509 -outform der -in mycert.pem -out mycert.der

Then I was able to import the certificate using:

keytool -keystore /location/of/keystore -import -alias mycertalias -file mycert.der