Search code examples
javajarappletjnlpjava-web-start

Deployed JNLP applet cannot find library: Incompatible magic value 1130458734


I am trying to deploy my applet using JNLP. I have tried using Eclipse Run Jetty Run plugin and it worked okay. But now with deployment at a real web server I am really stuck.

My jnlp file sketch is like this (I hava edited some names).

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" href="MyApplet.jnlp">
    <information>
        <title>MyApplet</title>
        <vendor>Me</vendor>
        <offline-allowed/>
    </information>
    <security>
        <j2ee-application-client-permissions/>
    </security>
    <resources>
        <!-- Application Resources -->
        <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
        <jar href="applet.jar" part="true" main="true"/>
        <jar href="log4j-1.2.16.jar" part="true"/>
        <jar href="slf4j-api-1.6.1.jar" part="true"/>
        <jar href="slf4j-log4j12-1.6.1.jar" part="true"/>
    </resources>
    <!--  Generate values dynamically -->
    <applet-desc main-class="org.project.applet.AppletMain" name="MyApplet" width="1600" height="860"/>
</jnlp>

I keep libraries in the same folder with applet.jar.

About manifest file in applet.jar I am not sure, I have tried many options, like specifying libraries, or just . Currently it is like below in Ant script

Java applet jnlp + libraries

<manifest>
    <attribute name="Class-Path" value="."/>
    <attribute name="Rsrc-Class-Path" value="./"/>
</manifest>

All jars are signed and this is what I get from console log:

basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 134206 us, pluginInit dt 7621660339 us, TotalTime: 7621794545 us
network: Cache entry not found [url: http://mydomain.com/play/, version: null]
network: Cache entry not found [url: http://mydomain.com/play/org/apache/log4j/Logger.class, version: null]
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with proxy=DIRECT
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with cookie "PHPSESSID=fe5gv8p4hp013r6i9p5aqjska5"
network: Connecting http://mydomain.com:80/ with proxy=DIRECT
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with cookie "PHPSESSID=fe5gv8p4hp013r6i9p5aqjska5"
basic: JNLP2ClassLoader.findClass: org.apache.log4j.Logger: try again ..
network: Cache entry not found [url: http://mydomain.com/play/org/apache/log4j/Logger.class, version: null]
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with proxy=DIRECT
network: Connecting http://mydomain.com/play/org/apache/log4j/Logger.class with cookie "PHPSESSID=fe5gv8p4hp013r6i9p5aqjska5"
basic: Dialog type is not candidate for embedding
basic: JNLP2ClassLoader.getPermissions() ..
network: Cache entry not found [url: http://mydomain.com/play/org/apache/log4j/Logger.class, version: null]
security: JAVAWS AppPolicy Permission requested for: http://mydomain.com/play/org/apache/log4j/Logger.class
basic: JNLP2ClassLoader.getPermissions() X
java.lang.ClassFormatError: Incompatible magic value 1130458734 in class file org/apache/log4j/Logger
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
    at sun.plugin2.applet.JNLP2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.project.applet.AppletMain.init(AppletMain.java:32)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
security: Reset deny session certificate store

Line 32 is

Logger.getRootLogger().setLevel(Level.OFF);

it is first class in applet which should be loaded from external library.

All jars, htmls and jnlps are in http://mydomain.com/play/ and I access applet http://mydomain.com/play/applet.html

From Incompatible magic value 1008813135 I have learned that 1130458734 means Cann and I really get Cannot find block '__global__' if access http://mydomain.com/play/org/apache/log4j/Logger.class.

But I don't understand why searching a class in jar fails, and why it tries to access http://mydomain.com/play/org/apache/log4j/Logger.class which never exist on the server.

EDIT:

My html file somewhere from Oracle tutorials:

<html>
<head>
    <title>MyApplet</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script src="http://www.java.com/js/deployJava.js"></script>
</head>
<body>
    <script>
        var attributes = {code:'org.project.applet.AppletMain', width:1600, height:860} ;
        var parameters = {jnlp_href: 'MyApplet.jnlp'} ;
        deployJava.runApplet(attributes, parameters, '1.6');
    </script>
</body>
</html>

Solution

  • Peter Lawrey:

    I assume the URL in the class path of applet and since the web server returns a message rather than some HTTP File Not Found status code it thinks it has a class it can use.

    That was a good guess! The webserver didn't not return 404 error in header for any non found resource, it was returning only some text. So Java interpreted it as if resource was found and was failing trying to load it as Java class.