Sign an Applet

From Processing

Jump to: navigation, search

By default Java applications are considered safe to run, or in Java speak trusted, since they are executed explicitly by users on their own computers. Applets by comparison are considered untrusted since they are initiated automatically in the browser. This restriction prevents applets from doing certain things, such as loading content from a different domain than the one hosting the applet. The error generated will look something like: access denied ( some URL here connect,resolve).

To override this restriction, you can can sign the applet.

There are a couple different approaches to signing an applet, but they each involve connecting a certificate to your jar file. Certificates are digital signatures that incorporate a public key with some identity. There are companies (Certificate Authorities) that sell certificates for hundreds of dollars, but it is also possible to create a self-sign certificate for free, which is the approach shown below.

The select_image sketch below the instructions attempts to load an image from your computer using a standard file browser. When run as an applet, it needs to be signed.

For more information, read <a href="">Chapter 10: Signed Applets</a> on the Sun website.


Assume you have a sketch named loadImage.pde

  1. Export your sketch as an applet, creating loadImage.jar. (Please note that if core.jar was also created, you have "Use multiple .jar files when exporting applets" checked in Processing's preferences window. I recommend unchecking this setting and re-exporting the sketch. Otherwise you'll need to sign both .jar files.
  2. Open a terminal program and navigate to the applet directory where loadImage.jar is located.
  3. type keytool -genkey -keystore pKeyStore -alias p5geek
  4. type keytool -selfcert -keystore pKeyStore -alias p5geek
  5. type jarsigner -keystore pKeyStore //loadImage//.jar p5geek
  6. Upload your applet

(Obviously, replace loadImage with the real name of your .jar file)

Source code

How to sign an applet taken from
@author Ira Greenberg
/* To run this sketch as an 
   applet, it MUST be signed */
void setup(){
  size(400, 400);
  PImage img;
  String imgName = selectInput();
  img = requestImage(imgName);
  while (img.width==0) delay(100); // Wait until image is loaded
  image(img, 0, 0);
Personal tools