我正在尝试一个来自Java Tutorials - Getting Started With Applets的简单的小程序演示,但是我遇到了浏览器总是显示NoClassDefFoundError的问题。
我有HelloWorld.java as
导入
javax.swing.*;
import.java.lang.reflect.InvocationTargetException;
public class HelloWorld extends JApplet{
public void init(){
try {
SwingUtilities.invokeAndWait(new Runnable(){
public void run(){
JLabel label = new JLabel("Hello World!");
add(label);
}
});
} catch (InterruptedException e) {
System.err.println("createGUI didn't complete successfully");
e.printStackTrace();
} catch (InvocationTargetException e) {
System.err.println("createGUI didn't complete successfully");
e.printStackTrace();
}
}
}和我的HelloWorld.html as
<html>
<head>
<title></title>
</head>
<body>
<p> This file launches the 'A' applet: A.class! </p>
<applet code="HelloWorld.class" height=200 width=320>
No Java?!
</applet>
</body>
</html>我将它们放在运行apache的debian机器上的/var/www/html/文件夹下,将此服务器添加到Java控制面板中的安全异常中,并尝试打开我遇到错误的http://ip_add_address_of_apache_server/HelloWorld.html
NoClassDefFoundError
HelloWorld$1HelloWorld.java在我的IDEA模块的根源文件夹下,它不在包中。
发布于 2015-08-01 04:11:59
代码的所有.class文件都需要在类路径中。我强烈建议您将代码打包到一个JAR文件中,并将该JAR放在HTML包装器中的类路径中。
https://stackoverflow.com/questions/31754408
复制相似问题