Assuming you are using a self-signed cert you need to use keytool and jarsigner. Everything replace everything within '<xxxxxx>', with your stuff.
1. Create keystore and key (Once only, you then reuse the keystore)
C:\<path to sdk>\bin\keytool -genkey -alias <e.g. yourname> -validity <time e.g. 5844> -keystore <name of your keystore>
You will be prompted to enter a password for the key and your name and address. Write the password down!
2. When you create a jar, sign it as follows
C:\<path_to_jdk>\bin\jarsigner -keystore <path to and name of your keystore> -storepass <your keystore password> -keypass <your key password> <your jar you want signed> <key name>
This works up to Java 1.5. Some command line options changed with Java 1.6, but I don't think it effected the above
The changes are as follows
keytool -genkey
pair -alias <alias> -validity <(optional) amount of time you want the certificate to be valid (default is 90 days)>
jarsigner -keystore <path to keystore> <path to jar> <alias>
After typing the keytool command, it is going to ask you a couple questions:
-password for the keystore
-your full name
-your organisational unit name
-your organisation name
-your city
-your state
-your two-letter country code (like for the United States is US)
-confirmation that all info is correct
-password for that alias, you may choose to use the same password as the keystore by pressing enter or use a different password
After typing the jarsigner command, it is going to ask you:
-password for the keystore
-password for the alias (only if you set it to a different one)
Then you're done
