0

My applet works in Eclipse when I run it with "Run As -> Java Applet", but when I try to launch it with a JNLP file, I get a NoClassDefFoundError. Im trying to use the javax.websocket-api inside my application, which uses the tyrus implementation.

Java code:

import javax.websocket.DeploymentException;
import org.glassfish.tyrus.server.Server;

public class MyApplet extends Applet {
    Server server = new Server("localhost", 8025, "/root/", MyApplet.class);
    try {
        server.start();
    }
    catch (DeploymentException e) {
        e.printStackTrace();
    }
}

Error message:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/websocket/DeploymentException
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/websocket/DeploymentException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.websocket.DeploymentException
    at sun.plugin2.applet.Plugin2ClassLoader$2.run(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)
    ... 24 more

Jnlp file:

<%@ page contentType="application/x-java-jnlp-file"%>
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.5" codebase="http://localhost:7001/root">
    <information>
        <title>title</title>
        <vendor>vendor</vendor>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <java version="1.7*"/>
        <jar href="my_applet.jar" main="true"/>
        <jar href="tyrus-websocket-core-1.1.jar"/>
        <jar href="activation-1.1.jar"/>
        <jar href="tyrus-container-grizzly-1.2.1.jar"/>
        <jar href="tyrus-core-1.1.jar"/>
        <jar href="tyrus-server-1.1.jar"/>
        <jar href="tyrus-spi-1.2.1.jar"/>
        <jar href="grizzly-framework-2.3.3.jar"/>
        <jar href="grizzly-http-2.3.3.jar"/>
        <jar href="grizzly-http-server-2.3.3.jar"/>
        <jar href="grizzly-rcm-2.3.3.jar"/>
        <jar href="javaee-api-7.0.jar"/>
        <jar href="javax.mail-1.5.0.jar"/>
        <jar href="jnlp-api-7.0.jar"/>
        <jar href="javax.websocket-api-1.0.jar"/>
    </resources>
    <applet-desc main-class="myPackage.MyApplet" name="name" width="100" height="10">
</applet-desc>

The jars given in the jnlp-file are exactly the same as in the Java Build Path specified in eclipse. The jar files are deployed on the server, I can access them with my web browser.

My idea would be that it has something to do with the websockets-api, which fails to load the tyrus implementation at runtime, but I have no idea how to fix it.

Jakob
  • 1,156
  • 3
  • 15
  • 26

1 Answers1

0

Turns out the error was caused by the Trusted-Library attribute in my MANIFEST.MF file. So, if anybody is having similar problems, check that your manifest file does not contain any errors and is consistent with your jnlp file.

Jakob
  • 1,156
  • 3
  • 15
  • 26