私のアプレットは "Run As - > Java Applet"で実行するとEclipseで動作しますが、JNLPファイルで起動しようとするとNoClassDefFoundError
となります。私のアプリケーション内でjavax.websocket-apiを使用しようとしていますが、これはtyrus実装を使用しています。NoClassDefFoundError with Java Web Start and Websocket
Javaコード:
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();
}
}
エラーメッセージ:
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ファイル:
<%@ 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>
jnlp-fileで指定されたjarは、eclipseで指定されたJava Build Pathとまったく同じです。 jarファイルはサーバーにデプロイされ、Webブラウザーでアクセスできます。
私の考えは、実行時にtyrusの実装を読み込むことができないwebsockets-apiと関係がありますが、修正方法はわかりません。