简体   繁体   中英

Applet won't run from GlassFish, Incompatible magic value. Runs fine from OS X web server

For a programming assignment, I am trying to have a GlassFish server serve up a client applet to talk to the server servlet. I've been stuck on having GlassFish deliver the applet. I have been searching extensively on this, and am not finding anything that resolves the issue - though I am learning quite a bit.

I have a 'hello world' applet compiled to tskApplet.class.

import java.applet.Applet;
import java.awt.*;
public class tskApplet extends Applet {
    public void paint (Graphics g) {
        g.drawString("Hello world! It's an applet!", 5, 25);
    }
}

I have an html page that loads the applet with the following applet tag:

<applet code = "tskApplet.class" width="300" height="300"></applet>

I've tried (to no avail) all sorts of variations such as putting the .class file in a .jar and including archive="tskApplet.jar" in the applet tag, and using a .jsp page, etc.

I'm using IntelliJ and if I run the tskApplet from an applet run/debug configuration it works fine. I followed this guide to set up GlassFish with ImtelliJ: http://wiki.jetbrains.net/intellij/Developing_applications_for_GlassFish_Server_in_IntelliJ_IDEA

If I copy the exact same .class file and .html file from the GlassFish server's web directory to the OS X Sites folder, then the applet works fine from the browser when I access it that way.

But if I run GlassFish and access my web application, the applet does not run. Instead I get these errors in the browser java console:

java.lang.ClassFormatError: Incompatible magic value 1768779887 in class file tskApplet
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:219)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:674)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:2990)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1481)
    at java.lang.Thread.run(Thread.java:680)

Any suggestions where to look next?

Sounds like GlassFish is running with an older JVM than the Applet was compiled with. Find out what JVM the server is running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM