How do I sign a Java applet for use in a browser?

user107312 picture user107312 · May 26, 2009 · Viewed 60.6k times · Source

I'm trying to deploy a Java applet on my website. I also need to sign it, because I need to access the clipboard. I've followed all the signing tutorials I could find but have not had any success. Here is what I've done so far:

  • Wrote an applet in NetBeans. It runs fine in the applet viewer.
  • Made a .jar file out of it.
  • Created a certificate by doing this:
keytool -genkey -keyalg rsa -alias myKeyName
keytool -export -alias myKeyName -file myCertName.crt
  • Signed it wtih jarsigner like this:
jarsigner "C:\my path\myJar.jar" myKeyName
  • Made an html file containing this:
<html>
  <body>
<applet code="my/path/name/myApplet.class" archive="../dist/myJar.jar"/>
  </body>
</html>

When I open that html file, I never get the security confirmation dialog box (and thus get the "java.security.AccessControlException: access denied" error). This happens on all browsers.

Am I missing a step?

Answer

nuno_cruz picture nuno_cruz · Dec 22, 2010

3 easy steps

  1. keytool -genkey -keystore myKeyStore -alias me

  2. keytool -selfcert -keystore myKeyStore -alias me

  3. jarsigner -keystore myKeyStore jarfile.jar me