当我使用" Run As - >运行它时,我的applet在Eclipse中工作。 Java Applet",但是当我尝试使用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$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文件中给出的jar与eclipse中指定的Java Build Path完全相同。 jar文件部署在服务器上,我可以使用我的Web浏览器访问它们。
我的想法是它与websockets-api有关,它无法在运行时加载tyrus实现,但我不知道如何解决它。
答案 0 :(得分:0)
原来错误是由Trusted-Library
文件中的MANIFEST.MF
属性引起的。因此,如果有任何人遇到类似问题,请检查您的清单文件是否包含任何错误,并且与您的jnlp文件一致。