keytool -genkey
is a dual operation: it generates a key-pair, and wraps it in a self-signed certificate.
Having this self-signed certificate really is just a convenience, partly linked to the storage format, that is just temporary if you want to use that key-pair for a CA-issued certificate.
You'll need to extract the certificate request from that key-pair, using the information you've entered when using -genkey
(this information ended up in the self-signed cert). Re-use the alias name you've used with -genkey
:
keytool -certreq -alias somename -file somename.csr -keystore mykeystore.jks
Send the CSR to your CA and, when you get the certificate back, re-import it against the same alias. This will overwrite the self-signed certificate that was generated initially, using keytool -importcert
. Beware you may need to import the whole chain at once, if there are intermediate certificates, as described at the end of this answer.