Java Web Start 和 Websockets 的 NoClassDefFoundError
NoClassDefFoundError with Java Web Start and Websockets
当我 运行 使用 "Run As -> Java Applet" 时,我的小程序在 Eclipse 中工作,但是当我尝试使用 JNLP 文件启动它时,我得到一个 NoClassDefFoundError
。我正在尝试在我的应用程序中使用 javax.websocket-api,它使用 tyrus 实现。
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.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.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.run(Unknown Source)
at java.awt.EventQueue.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.run(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.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 文件中给出的 jars 与在 eclipse 中指定的 Java Build Path 完全相同。 jar 文件部署在服务器上,我可以使用我的网络浏览器访问它们。
我的想法是它与 websockets-api 有关,它无法在 运行 时加载 tyrus 实现,但我不知道如何修复它。
原来错误是由我的 MANIFEST.MF
文件中的 Trusted-Library
属性引起的。因此,如果有人遇到类似问题,请检查您的清单文件是否不包含任何错误并且与您的 jnlp 文件一致。
当我 运行 使用 "Run As -> Java Applet" 时,我的小程序在 Eclipse 中工作,但是当我尝试使用 JNLP 文件启动它时,我得到一个 NoClassDefFoundError
。我正在尝试在我的应用程序中使用 javax.websocket-api,它使用 tyrus 实现。
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.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.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.run(Unknown Source)
at java.awt.EventQueue.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.run(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.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 文件中给出的 jars 与在 eclipse 中指定的 Java Build Path 完全相同。 jar 文件部署在服务器上,我可以使用我的网络浏览器访问它们。
我的想法是它与 websockets-api 有关,它无法在 运行 时加载 tyrus 实现,但我不知道如何修复它。
原来错误是由我的 MANIFEST.MF
文件中的 Trusted-Library
属性引起的。因此,如果有人遇到类似问题,请检查您的清单文件是否不包含任何错误并且与您的 jnlp 文件一致。