Creating a Java Applet in 2013

Creating applets used to be easy somewhere in the distant past. Now it’s a bit more complicated …

  • You need so sign the applet. There’s no way around that, if you don’t want 3 warning popups. (and unsigned code will be disabled as described in an upcoming update, see https://blogs.oracle.com/java-platform-group/entry/new_security_requirements_for_rias)
  • you’ll get different levels of restrictiveness depending on the jre version you are using – in Java 7, there were several updates that increasingly tightened the restrictions (e.g. update 21, update 25, update 45)
  • you need to add Permissions and Codebase Manifest entries (and throw in an Application-Name too), like
    Permissions: sandbox
    Codebase: your.app.com
    Application-Name: YourApp
    
  • if you use the sandbox permission (the other option is all-permissions), you need to specify this also in the embedding htmlpage, otherwise you’ll get a java.lang.SecurityException: “JAR manifest requested to run in sandbox only”, respectively “JAR manifest requested to run in all-permissons only”
    <param name="permissions" value="sandbox" />
    

    Depending which variant of using the applet you are using, you might need to add the permissions as attributes to the html tag

    <embed permissions="sandbox" code="${appletClass}" archive="${jars}" />
    
  • if you use all-permissions, the user still needs to accept one dialog (with the option of not popping it up again for this applet)
  • another tip: when providing a text file with the manifest entries, add a newline at the end of the file, otherwise the last entry will be ignored
  • Conclusio: consider using a different technology (these days, flash doesn’t have much lure either). Oracle doesn’t seem keen to make your life with applets easier, and applets don’t run on mobile clients … so welcome to Canvas, jQuery and tons of interesting Javascript frameworks (most applets do some drawing, so why not use processing.js?).
This entry was posted in Software. Bookmark the permalink.