Modified: 11/20/2007, Created: 11/20/2007

The Applet Stuff: Processing.org, Groovy and Maven Together

If you must use an Applet in a web broswer. Here is what I found worked for me. There are still some limitations.

  • If your Applet is written in Groovy, you will need to compile it.
  • You can run it locally viewed in a web browser on your desktop; however, these instructions will not help you offer the web page with Applet be downloaded and run by others.

Method 1:

  • Start up the Processing PDE.
  • Create an empty sketch.
  • Save the sketch.
  • Export the sketch.
  • Using a File Explorer, navigate to where the sketch was saved. Change Directory into the "applet" folder created by the export action.
  • Modify the index.html The main point here is to add "groovy-all-1.1-rc-2.jar" to the list of library files. In file index.html, change
            archive="sketch_071112a.jar,core.jar"
    ...
                                            <param name="archive" value="sketch_071112a.jar,core.jar" />
    ...
                                            <param name="archive" value="sketch_071112a.jar,core.jar" />
    

    to

            archive="sketch_071112a.jar,core.jar,groovy-all-1.1-rc-2.jar"
    ...
                                            <param name="archive" value="sketch_071112a.jar,core.jar,groovy-all-1.1-rc-2.jar" />
    ...
                                            <param name="archive" value="sketch_071112a.jar,core.jar,groovy-all-1.1-rc-2.jar" />
    

    Where sketch_071112a should be adjusted to your actual sketch name.

Method 2:

  • Edit this template index.html file listing instead of creating it from Processing's IDE
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                    <!-- charset must remain utf-8 to be handled properly by Processing -->
                    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
                    
                    <title>sketch_071112a : Built with Processing</title>
                    
                    <style type="text/css">
                    /* <![CDATA[ */
            
                    body {
                      margin: 60px 0px 0px 55px;
                      font-family: verdana, geneva, arial, helvetica, sans-serif; 
                      font-size: 11px; 
                      background-color: #ddddcc; 
                      text-decoration: none; 
                      font-weight: normal; 
                      line-height: normal; 
                    }
                     
                    a          { color: #3399cc; }
                    a:link     { color: #3399cc; text-decoration: underline; }
                    a:visited  { color: #3399cc; text-decoration: underline; }
                    a:active   { color: #3399cc; text-decoration: underline; }
                    a:hover    { color: #3399cc; text-decoration: underline; }
            
                    /* ]]> */
                    </style>
             
            </head>
            <body>
                    <div id="content">
                            <div id="sketch_071112a_container">
                            
                            <!--[if !IE]> -->
                                    <object classid="java:sketch_071112a.class" 
                                    type="application/x-java-applet"
                                    archive="sketch_071112a.jar,core.jar"
                                    width="200" height="200"
                                    standby="Loading Processing software..." >
                                    
                                            <param name="archive" value="sketch_071112a.jar,core.jar" />
                                    
                                            <param name="mayscript" value="true" />
                                            <param name="scriptable" value="true" />
                                    
                                            <param name="image" value="loading.gif" />
                                            <param name="boxmessage" value="Loading Processing software..." />
                                            <param name="boxbgcolor" value="#FFFFFF" />
                                    
                                            <param name="test_string" value="outer" />
                            <!--<![endif]-->
                                    
                                    <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
                                                    codebase="http://java.sun.com/update/1.4.2/jinstall-1_4_2_12-windows-i586.cab"
                                                    width="200" height="200"
                                                    standby="Loading Processing software..."  >
                                                    
                                            <param name="code" value="sketch_071112a" />
                                            <param name="archive" value="sketch_071112a.jar,core.jar" />
                                            
                                            <param name="mayscript" value="true" />
                                            <param name="scriptable" value="true" />
                                            
                                            <param name="image" value="loading.gif" />
                                            <param name="boxmessage" value="Loading Processing software..." />
                                            <param name="boxbgcolor" value="#FFFFFF" />
                                            
                                            <param name="test_string" value="inner" />
                                            
                                            <p>
                                                    <strong>
                                                            This browser does not have a Java Plug-in.
                                                            <br />
                                                            <a href="http://java.sun.com/products/plugin/downloads/index.html" title="Download Java Plug-in">
                                                                    Get the latest Java Plug-in here.
                                                            </a>
                                                    </strong>
                                            </p>
                                    
                                    </object>
                                    
                            <!--[if !IE]> -->
                                    </object>
                            <!--<![endif]-->
                            
                            </div>
                            
                            <p>
                            
                            </p>
                            
    <!--
                            <p>
                            Source code: <a href="sketch_071112a.pde">sketch_071112a</a> 
                            </p>
    -->
                            
                            <p>
                            Built with <a href="http://processing.org" title="Processing.org">Processing</a>
                            </p>
                    </div>
            </body>
    </html>
    

    Edit sketch_071112a to be your actual sketch name.

Common to Both Methods

  • Ensure that the class and jar files needed are available and in the correct location.
  • You will need to find where your java.policy file is located. Look for it in lib/security where your JRE was installed.

    Example: C:\Program Files\java\jre1.6.0_03\lib\security\java.policy

  • Here is the scary part. Add the following entry adjusting the "file:..." to be a path where your Applet is located.

    NOTE: You are responsible for any security harm that may be done to you if you add the following entry.

    grant codeBase "file:/C:/dev/projects/path/to/applet/-" {
            permission java.security.AllPermission;
    };