Question

I have done a few Java programs but this is the first one that I'm trying to run as an applet so I might have some basic error.

I compiled all the classes and put them together in a jar file called final. I followed a few tutorials to make a JNLP file that I called jnlp (yeah, I know, I'm very original:) and on which I called to my jar file and I called the JNLP file from an HTML file.

Those are the last lines of the java console output: (before them, the console is filled with my JNLP file)

at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
preloader: Added pending event 2: ErrorEvent[url=null label=JNLP not an applet, nor a JavaFX application cause=JNLP not an applet, nor a JavaFX application

Here is the JNLP file:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="jnlp.jnlp">
    <information>
        <title>Encryption Software</title>
        <vendor>Atlantis Atlantis</vendor>
        <icon href="encrypt_logo.jpg"/>
        <offline-allowed/>
    </information>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+" href=
           "http://java.sun.com/products/autodl/j2se"/>
        <jar href="final.jar"
            main="true" />

    </resources>
    <application-desc
         name="Encryption Software"
         main-class="EncryptApplication"
         width="500"
         height="300">
     </application-desc>
     <update check="background"/>
</jnlp>

Here is the JS used to launch the applet:

<script src="https://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {code:'', width:500, height:500};
    var parameters = {jnlp_href: 'jnlp.jnlp'};
    deployJava.runApplet(attributes, parameters, '1.6');
</script>
Was it helpful?

Solution

Is the EncryptionApplication really an applet? To be an applet it must extend Applet or JApplet.

If it is not an applet, it cannot be embedded in HTML.

If it is an applet, the JNLP must declare it as such, so:

    <application-desc
         name="Encryption Software"
         main-class="EncryptApplication"
         width="500"
         height="300">
     </application-desc>

Should be:

    <applet-desc
         name="Encryption Software"
         main-class="EncryptApplication"
         width="500"
         height="300">
     </applet-desc>

Tips

  • Be sure to check the JNLP using JaNeLA.
  • Avoid applets like you might avoid the plague. They were always a complete PITA and with recent security updates, have only become more so. See Why CS teachers should stop teaching Java applets for my take on the matter.
  • It is possible to launch an application (e.g. a JFrame based app.) from a link using Java Web Start. They will be subject to the same (very strict) security requirements of applets, but have none of the applet specific problems (see link in previous point for details).
  • As mentioned by @ElliottFrisch, it is best to include a valid value for the code attribute. There are circumstances in which it can be left out, but I won't get into that right now..
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top