How to automate Keystore generation using the java keystore tool? w/o user interaction

Try this:

keytool -genkey -noprompt \
 -alias alias1 \
 -dname "CN=mqttserver.ibm.com, OU=ID, O=IBM, L=Hursley, S=Hants, C=GB" \
 -keystore keystore \
 -storepass password \
 -keypass password

don't forget -noprompt, otherwise you will be asked to input Yes or No


See the full documentation about command line or by typing keytool without any arguments.

Specifically you may want to look options -storepass password -keypass password