Using JOGL in a Java applet: Difference between revisions

From JogampWiki
Jump to navigation Jump to search
(Created page with 'You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java applet, which lets you run Java programs embedded in a web page. This page shows an …')
 
No edit summary
 
(48 intermediate revisions by 2 users not shown)
Line 1: Line 1:
You can use JOGL in a [http://download.oracle.com/javase/6/docs/technotes/guides/javaws/ Java applet, which lets you run Java programs embedded in a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a fixed-size frame in a web page.
N.B: [https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free The Java Plugin is deprecated in Oracle Java 1.9], it will be removed from future JavaSE releases and it won't be supported in the major web browsers at the end of 2016. As a consequence, you are highly encouraged to stop developing Java applets.
 
= Preface =
You can use JOGL in a [http://java.sun.com/applets/ Java applet], which lets you run a Java program embedded in a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a fixed-size frame in a web page.
 
You can see online examples here: [{{SERVER}}/deployment/jogamp-current/jogl-test-applets.html JOGL Test Applets]
 
Documented Examples using the Object/Embed tags:
* Normal-Applet using native-JAR lib loading
** [{{SERVER}}/deployment/jogamp-current/jogl-applet-runner-newt-gears-normal-napplet.html ''Demo and modules on jogamp.org'']
** [http://jausoft.com/jogamp/jogl-applet-runner-newt-gears-normal-napplet.html ''Demo on jausoft.com and modules on jogamp.org'']
* JNLP-Applet w/ JNLPLauncher fallback
** [{{SERVER}}/deployment/jogamp-current/jogl-applet-runner-newt-gears-normal.html ''Demo and modules on jogamp.org'']
** [http://jausoft.com/jogamp/jogl-applet-runner-newt-gears-normal.html ''Demo on jausoft.com and modules on jogamp.org'']
* JNLPLauncher only
** [{{SERVER}}/deployment/jogamp-current/jogl-applet-runner-newt-gears-normal-launcheronly.html ''Demo and modules on jogamp.org'']
** [http://jausoft.com/jogamp/jogl-applet-runner-newt-gears-normal-launcheronly.html ''Demo on jausoft.com and modules on jogamp.org'']
 
A short ''copy'' is included in the static page [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#NApplets JOGL Deployment as a New Applet].


= Base class =
= Base class =
Line 35: Line 53:


     public void init() {
     public void init() {
         GLProfile.initSingleton( false );
         GLProfile.initSingleton();
         setLayout( new BorderLayout() );
         setLayout( new BorderLayout() );


Line 77: Line 95:
}
}
</pre>
</pre>
= Applet web page =
Finally, the applet needs a web page to display in. Note that this file sets the fixed size of the applet window. Copy this code to a file called <tt>OneTriangleApplet.html</tt>.
== Using JogAmp's Signed Jar and Jnlp Files ==
The URL <code>http://jogamp.org/deployment/jogamp-current/</code> specifies
JogAmp's location of released signed Jar and JNLP files.
Currently supported locations are:
* http://jogamp.org/deployment/jogamp-current/ - Current Release
* http://jogamp.org/deployment/jogamp-next/ - Next Release
* http://jogamp.org/deployment/v2.0-rc10/ - Specific Version
=== [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#NApplets NApplet] using native-JAR lib loading ===
The html snippet, for <tt>OneTriangleNApplet.html</tt>:
<pre>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      width="200" height="200">
  <param name="code" value="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet">
  <param name="archive" value="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                                http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                                onetriangle.jar">
  <comment>
    <embed code="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet"
          width="200" height="200"
          type="application/x-java-applet;version=1.6"
          pluginspage="http://java.sun.com/javase/downloads/ea.jsp"
          archive="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                  http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                  onetriangle.jar">
        <noembed>Sorry, no Java support detected.</noembed>
    </embed>
  </comment>
</object>
</pre>
Examples:
* [http://jausoft.com/jogamp/jogl-applet-runner-newt-gears-normal-napplet.html ''Demo on jausoft.com and modules on jogamp.org'']
* [{{SERVER}}/deployment/jogamp-current/jogl-applet-runner-newt-gears-normal-napplet.html ''Demo and modules on jogamp.org'']
=== JNLP-Applet w/ [{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#NApplets NApplet] fallback ===
The html snippet, for <tt>OneTriangleApplet.html</tt>:
<pre>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      width="200" height="200">
  <param name="code" value="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet">
  <param name="archive" value="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                                http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                                onetriangle.jar">
  <param name="jnlp_href" value="OneTriangleApplet.jnlp">
  <comment>
    <embed code="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet"
          width="200" height="200"
          type="application/x-java-applet;version=1.6"
          pluginspage="http://java.sun.com/javase/downloads/ea.jsp"
          archive="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                  http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                  onetriangle.jar"
          jnlp_href="OneTriangleApplet.jnlp">
        <noembed>Sorry, no Java support detected.</noembed>
    </embed>
  </comment>
</object>
</pre>
<tt>OneTriangleApplet.jnlp</tt>:
<pre>
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="./"
  href="OneTriangleApplet.jnlp">
  <information>
    <title>OneTriangle Demo</title>
    <vendor>JogAmp Community</vendor>
    <homepage href="http://jogamp.org/"/>
    <description>OneTriangle Java Web Start Demo</description>
    <description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description>
    <offline-allowed/>
  </information>
  <update check="background" policy="always"/>
  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
    <extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" />
    <jar href="onetriangle.jar" main="true"/>
  </resources>
  <applet-desc
      name="OneTriangle Applet"
      main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet"
      width="200"
      height="200">
  </applet-desc>
</jnlp>
</pre>
Examples:
** [http://jausoft.com/jogamp/jogl-applet-runner-newt-gears-normal.html ''Demo on jausoft.com and modules on jogamp.org'']
** [{{SERVER}}/deployment/jogamp-current/jogl-applet-runner-newt-gears-normal.html ''Demo and modules on jogamp.org'']
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.
== Using Your own Signed Jar and Jnlp Files ==
In case you prefer to use your own JogAmp files, just replace the above JogAmp URL
with your own and sign the Jar files of your JogAmp files with your own valid key, or test key as described below.
Don't sign your own applet code's JAR file(s).
= Setting up the applet directory =
Note that none of your applet Jar files needs to be signed. Only the Jogamp files (GlueGen, JOGL, ..) require code signing.
* Create a directory to hold your applet.
* Put your <tt>OneTriangleApplet.html</tt> file in that new directory.
* Create a subdirectory <tt>name/wadewalker/jogl2tests/onetriangle</tt> inside your applet directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.
* Put your <tt>OneTriangle.java</tt> and <tt>OneTriangleAWT.java</tt> files inside the subdirectory.
If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.
== Using Your own Signed Jar and Jnlp Files ==
* Copy all the JogAmp Jar files ([[{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#GluegenJARs|GlueGen]] and [[{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JOGLAllInOneJARs|JOGL]]) into the applet directory as described [https://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start#Setting_up_the_application_directory here] and sign them (see below).
* Copy <tt>applet-launcher.jar</tt> into the applet directory and sign it (see below). Currently this file is not part of the JOGL distribution. I built it from source I downloaded from [https://github.com/sgothel/applet-launcher Sven's repository].
* Copy the JogAmp [[{{SERVER}}/jogl/doc/deployment/JOGL-DEPLOYMENT.html#JNLPFiles|Jnlp files]] into that applet directory
=== Signing the JogAmp Jar Files ===
All the JogAmp Jar files your applet uses must be signed to work correctly in a web browser. Do this just as in the [https://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start#Signing_your_JARs Java Web Start case], with one addition for the applet launcher JAR:
<pre>
jarsigner -keystore testKeys applet-launcher.jar ww
</pre>
= Compiling and JARing your program =
You can compile and JAR the program exactly as we did for the [https://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start#Compiling_and_JARing_your_program Java Web Start case].
= Writing the JNLP files =
New-style Java applets use two [http://download.oracle.com/javase/1,5.0/docs/guide/javaws/developersguide/syntax.html Java Network Launching Protocol (JNLP)] files to find the JAR files that make up the applet. Create both JNLP files exactly as in the [https://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start#Writing_the_JNLP_files Java Web Start case].
= Running the applet in a browser =
To run the applet in a browser on Windows, right-click the <tt>OneTriangleApplet.html</tt> file and click "Open with > Internet Explorer|Chrome|Firefox|Safari". The result should look like this:
[[File:Applet-browser-test.png|300px|thumb|none|Applet OneTriangle in IE 9]]
= Clearing the applet cache =
Java caches applet JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because Java is still using the cached copy.
* To clear the cache on Windows:
** From the control panel: click <tt>Start > Control Panel > Java</tt>, then click <tt>Temporary Internet Files</tt>, click <tt> Settings...</tt>, click <tt>Delete Files...</tt>, and click <tt>OK</tt>.
** From the command line: delete <tt>%USERPROFILE%\AppData\LocalLow\Sun\Java\Deployment\cache</tt>.
* To clear the cache on Mac OS X:
** From the control panel: click <tt>Dock > Applications > Utilities > Java Preferences.app</tt>, then click the <tt>Network tab</tt>, click <tt>Delete Files...</tt>, and click <tt>OK</tt>.
** From the command line: delete <tt>~/Library/Caches/Java/cache</tt>
The JNLPAppletLauncher (if it's used) may also cache files. You can clear its cache on Windows by deleting <tt>%USERPROFILE%\.jnlp-applet</tt>, and on Mac OS X by deleting <tt>~/.jnlp-applet</tt>.
= Running the applet with the Java applet viewer =
The Java JDK comes with a program called <tt>appletviewer</tt>, which you can use to launch your applet from the command line without the use of a browser. This viewer works the way that older Java browser plugins used to work (and the way Safari's plugin still works), so it can help test compatibility.
When you launch with <tt>appletviewer</tt>, it also uses the <tt>JNLPAppletLauncher</tt> class that we specified in <tt>OneTriangleApplet.html</tt>, which the newer Java plugins seem to ignore.
The downside of that is the <tt>JNLPAppletLauncher</tt> doesn't yet support relative paths, so you'll need to change the value of <tt>jnlpExtension1</tt> in <tt>OneTriangleApplet.html</tt> from <tt>"./"</tt> to an absolute path like <tt>"file://localhost/C:/Users/my/applet/dir/JOGL.jnlp"</tt>, and the value of <tt>codebase</tt> in <tt>JOGL.jnlp</tt> from <tt>"./"</tt> to an absolute path like <tt>"file://localhost/C:/Users/my/applet/dir/"</tt>.
Then, to give the applet the permissions it needs to run outside the browser, create a file named <tt>all.policy</tt> in your applet directory, and put this text in it:
<pre>
grant {
  permission java.security.AllPermission;
};
</pre>
Then finally you can launch the applet from the command line like this:
<tt>appletviewer -J-Djava.security.policy=all.policy OneTriangleApplet.html</tt>
The result should look like this:
[[File:applet-viewer-test.png|300px|thumb|none|Applet OneTriangle in appletviewer]]
You can also use the applet viewer to remotely debug your code like this:
<tt>appletviewer -J-Djava.security.policy=all.policy -J-Xdebug -J-Djava.compiler=NONE -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 OneTriangleApplet.html</tt>
When you hit return, the applet will suspend on startup, so you can connect to the applet process with your debugger of choice.
= Running the applet from inside Eclipse =
'''*This section is unfinished*'''
If you set up your applet as an Eclipse project, you can run it in the applet viewer by right-clicking the applet project and clicking "Run As > Java Applet". This is similar to running the applet via <tt>appletviewer</tt> on the command line, but allows local instead of remote debugging.
= Running the applet from a web server =
'''*This section is unfinished*'''
Once you're sure that the applet launches correctly from the local file system, you're ready to deploy it to a web server.
* Create or choose an applet directory on your web server.
* Change the <tt>codebase</tt> entries in the JNLP from directory names to URLs that refer to the applet directory on your web server.
* Copy all the HTML, JAR, and JNLP files from your local applet directory to the applet directory on your web server.
* Put a link to the <tt>OneTriangleApplet.html</tt> file on a page on your web server so users can find your applet page.

Latest revision as of 14:42, 4 February 2016

N.B: The Java Plugin is deprecated in Oracle Java 1.9, it will be removed from future JavaSE releases and it won't be supported in the major web browsers at the end of 2016. As a consequence, you are highly encouraged to stop developing Java applets.

Preface

You can use JOGL in a Java applet, which lets you run a Java program embedded in a web page. This page shows an example of how to do this. The example program just draws one triangle that fills a fixed-size frame in a web page.

You can see online examples here: JOGL Test Applets

Documented Examples using the Object/Embed tags:

A short copy is included in the static page JOGL Deployment as a New Applet.

Base class

We'll use the same triangle-drawing base class for this example that we did in the Java Web Start example. Copy the code to a file called OneTriangle.java.

Applet class

Now we need a simple class that extends java.applet.Applet to form the top level of our program. Copy this code to a file called OneTriangleAWTApplet.java.

package name.wadewalker.jogl2tests.onetriangle;

import java.applet.*;
import java.awt.*;

import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

import com.jogamp.opengl.util.FPSAnimator;

/**
 * A minimal applet that draws with JOGL in a browser window.
 *
 * @author Wade Walker
 */
@SuppressWarnings("serial")
public class OneTriangleAWTApplet extends Applet {

    private GLAnimatorControl glanimatorcontrol;

    public void init() {
        GLProfile.initSingleton();
        setLayout( new BorderLayout() );

        final GLCanvas glcanvas = new GLCanvas();
        glcanvas.addGLEventListener( new GLEventListener() {
            
            @Override
            public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {
                OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height );
            }
            
            @Override
            public void init( GLAutoDrawable glautodrawable ) {
            }
            
            @Override
            public void dispose( GLAutoDrawable glautodrawable ) {
            }
            
            @Override
            public void display( GLAutoDrawable glautodrawable ) {
                OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getWidth(), glautodrawable.getHeight() );
            }
        });
    
        glcanvas.setSize( getSize() );
        add( glcanvas, BorderLayout.CENTER );
        glanimatorcontrol = new FPSAnimator( glcanvas, 30 );
    }

    public void start() {
        glanimatorcontrol.start();
    }
    
    public void stop() {
        glanimatorcontrol.stop();
    }
    
    public void destroy() {
    }
}

Applet web page

Finally, the applet needs a web page to display in. Note that this file sets the fixed size of the applet window. Copy this code to a file called OneTriangleApplet.html.

Using JogAmp's Signed Jar and Jnlp Files

The URL http://jogamp.org/deployment/jogamp-current/ specifies JogAmp's location of released signed Jar and JNLP files. Currently supported locations are:

NApplet using native-JAR lib loading

The html snippet, for OneTriangleNApplet.html:

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      width="200" height="200">
   <param name="code" value="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet">
   <param name="archive" value="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                                http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                                onetriangle.jar">
   <comment>
     <embed code="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet"
          width="200" height="200"
          type="application/x-java-applet;version=1.6"
          pluginspage="http://java.sun.com/javase/downloads/ea.jsp"
          archive="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                   http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                   onetriangle.jar">
        <noembed>Sorry, no Java support detected.</noembed>
     </embed>
   </comment>
</object>

Examples:

JNLP-Applet w/ NApplet fallback

The html snippet, for OneTriangleApplet.html:

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      width="200" height="200">
   <param name="code" value="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet">
   <param name="archive" value="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                                http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                                onetriangle.jar">
   <param name="jnlp_href" value="OneTriangleApplet.jnlp">
   <comment>
     <embed code="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet"
          width="200" height="200"
          type="application/x-java-applet;version=1.6"
          pluginspage="http://java.sun.com/javase/downloads/ea.jsp"
          archive="http://jogamp.org/deployment/jogamp-current/jar/gluegen-rt.jar,
                   http://jogamp.org/deployment/jogamp-current/jar/jogl-all.jar,
                   onetriangle.jar"
          jnlp_href="OneTriangleApplet.jnlp">
        <noembed>Sorry, no Java support detected.</noembed>
     </embed>
   </comment>
</object>

OneTriangleApplet.jnlp:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="./"
  href="OneTriangleApplet.jnlp">

  <information>
    <title>OneTriangle Demo</title>
    <vendor>JogAmp Community</vendor>
    <homepage href="http://jogamp.org/"/>
    <description>OneTriangle Java Web Start Demo</description>
    <description kind="short">The simplest possible JOGL Java Web Start demo - draws one triangle.</description>
    <offline-allowed/>
  </information>
  <update check="background" policy="always"/>

  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/>
    <extension name="jogl-all-awt" href="http://jogamp.org/deployment/jogamp-current/jogl-all-awt.jnlp" />
    <jar href="onetriangle.jar" main="true"/>
  </resources>

  <applet-desc 
      name="OneTriangle Applet"
      main-class="name.wadewalker.jogl2tests.onetriangle.OneTriangleAWTApplet"
      width="200" 
      height="200">
  </applet-desc>
</jnlp>

Examples:

If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.

Using Your own Signed Jar and Jnlp Files

In case you prefer to use your own JogAmp files, just replace the above JogAmp URL with your own and sign the Jar files of your JogAmp files with your own valid key, or test key as described below. Don't sign your own applet code's JAR file(s).

Setting up the applet directory

Note that none of your applet Jar files needs to be signed. Only the Jogamp files (GlueGen, JOGL, ..) require code signing.

  • Create a directory to hold your applet.
  • Put your OneTriangleApplet.html file in that new directory.
  • Create a subdirectory name/wadewalker/jogl2tests/onetriangle inside your applet directory. Or if you changed the packages of the files above, create a subdirectory that matches your package names.
  • Put your OneTriangle.java and OneTriangleAWT.java files inside the subdirectory.

If you decide to use our JogAmp signed Jar and Jnlp files you can skip the next chapter.

Using Your own Signed Jar and Jnlp Files

  • Copy all the JogAmp Jar files ([[1]] and [[2]]) into the applet directory as described here and sign them (see below).
  • Copy applet-launcher.jar into the applet directory and sign it (see below). Currently this file is not part of the JOGL distribution. I built it from source I downloaded from Sven's repository.
  • Copy the JogAmp [files] into that applet directory

Signing the JogAmp Jar Files

All the JogAmp Jar files your applet uses must be signed to work correctly in a web browser. Do this just as in the Java Web Start case, with one addition for the applet launcher JAR:

jarsigner -keystore testKeys applet-launcher.jar ww

Compiling and JARing your program

You can compile and JAR the program exactly as we did for the Java Web Start case.

Writing the JNLP files

New-style Java applets use two Java Network Launching Protocol (JNLP) files to find the JAR files that make up the applet. Create both JNLP files exactly as in the Java Web Start case.

Running the applet in a browser

To run the applet in a browser on Windows, right-click the OneTriangleApplet.html file and click "Open with > Internet Explorer|Chrome|Firefox|Safari". The result should look like this:

Applet OneTriangle in IE 9

Clearing the applet cache

Java caches applet JAR and JNLP files to reduce load time. Unfortunately, if you edit one of these files and re-launch, sometimes you won't see your changes because Java is still using the cached copy.

  • To clear the cache on Windows:
    • From the control panel: click Start > Control Panel > Java, then click Temporary Internet Files, click Settings..., click Delete Files..., and click OK.
    • From the command line: delete %USERPROFILE%\AppData\LocalLow\Sun\Java\Deployment\cache.
  • To clear the cache on Mac OS X:
    • From the control panel: click Dock > Applications > Utilities > Java Preferences.app, then click the Network tab, click Delete Files..., and click OK.
    • From the command line: delete ~/Library/Caches/Java/cache

The JNLPAppletLauncher (if it's used) may also cache files. You can clear its cache on Windows by deleting %USERPROFILE%\.jnlp-applet, and on Mac OS X by deleting ~/.jnlp-applet.

Running the applet with the Java applet viewer

The Java JDK comes with a program called appletviewer, which you can use to launch your applet from the command line without the use of a browser. This viewer works the way that older Java browser plugins used to work (and the way Safari's plugin still works), so it can help test compatibility.

When you launch with appletviewer, it also uses the JNLPAppletLauncher class that we specified in OneTriangleApplet.html, which the newer Java plugins seem to ignore.

The downside of that is the JNLPAppletLauncher doesn't yet support relative paths, so you'll need to change the value of jnlpExtension1 in OneTriangleApplet.html from "./" to an absolute path like "file://localhost/C:/Users/my/applet/dir/JOGL.jnlp", and the value of codebase in JOGL.jnlp from "./" to an absolute path like "file://localhost/C:/Users/my/applet/dir/".

Then, to give the applet the permissions it needs to run outside the browser, create a file named all.policy in your applet directory, and put this text in it:

grant {
  permission java.security.AllPermission;
};

Then finally you can launch the applet from the command line like this:

appletviewer -J-Djava.security.policy=all.policy OneTriangleApplet.html

The result should look like this:

Applet OneTriangle in appletviewer

You can also use the applet viewer to remotely debug your code like this:

appletviewer -J-Djava.security.policy=all.policy -J-Xdebug -J-Djava.compiler=NONE -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 OneTriangleApplet.html

When you hit return, the applet will suspend on startup, so you can connect to the applet process with your debugger of choice.

Running the applet from inside Eclipse

*This section is unfinished*

If you set up your applet as an Eclipse project, you can run it in the applet viewer by right-clicking the applet project and clicking "Run As > Java Applet". This is similar to running the applet via appletviewer on the command line, but allows local instead of remote debugging.

Running the applet from a web server

*This section is unfinished*

Once you're sure that the applet launches correctly from the local file system, you're ready to deploy it to a web server.

  • Create or choose an applet directory on your web server.
  • Change the codebase entries in the JNLP from directory names to URLs that refer to the applet directory on your web server.
  • Copy all the HTML, JAR, and JNLP files from your local applet directory to the applet directory on your web server.
  • Put a link to the OneTriangleApplet.html file on a page on your web server so users can find your applet page.