Work in steps:-
- Set Applet Permissions
- Compile the Applet
- Generate the Jar file
- Generate Keys
- Self certify
- Sign the JAR File
You can set the permissions that your applet wants to run correctly in its init method, those are a sample permissions:
private void setPolicyPermissions() throws MalformedURLException {
Policy policy = Policy.getPolicy();
PermissionCollection permissions = policy.getPermissions(new CodeSource(new URL(getParameter("CODE_SOURCE_URL")),
new Certificate[0]));
RuntimePermission accessClassPermission = new RuntimePermission("accessClassInPackage.sun.awt.windows");
permissions.add(accessClassPermission);
}
You can see the available permissions in Java. and choose the suitable for your mission.
In your working directory, use the javac command to generate the class file:
javac MyApplet.java
Now it's the time to generate a jar file to contain the .class files, so we'll use the jar command to finish this task:
jar -cvf MyApplet.jar *.class
Here we'll generate the needed keys to sign the jar file to be enabled to run at the client and use his machine resources safely using the keytool command. the prompt will ask you for a password to the key and another one for the store... handle that:
keytool -genkey -alias MyKey -keypass KeyPass
we'll use the keytool command again to make our key self certify. (i think that command used instead of using the private and public key):
keytool -selfcert -alias MyKey
JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, jarsigner to make a signed copy of the MyApplet.jar file:
jarsigner -storepass StroePass -keypass KeyPass MyApplet.jar MyKey