I realize there's a million of these posts but none of them have helped me so here goes: I'm trying to deploy a very, very simple applet that will not load properly. My HTML:
<html>
<head>
<meta http-equiv="Content-Type" content"text/html; charset=utf-8">
</head>
<body>
<applet code = "SimpleApplet.class"
width = "320" height = "100"></applet>
</body>
</html>
My Java:
package test;
import javax.swing.*;
public class SimpleApplet extends JApplet{
public void init(){
try{
SwingUtilities.invokeAndWait(new Runnable(){
public void run(){
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
}
catch(Exception e){
System.out.println(e);
}
}
}
Both files are located in the same directory
/home/me/workspace/myProject/bin/test
If I run the applet on its own via Eclipse, it works fine. When I open the page I get the error
java.lang.NoClassDefFoundError: SimpleApplet (wrong name: test/SimpleApplet)
The error would suggest that I have incorrectly placed or named something. However, after trying
<applet code = "test/SimpleApplet.class"
width = "320" height = "100"></applet>
<applet code = "SimpleApplet.class"
codebase = "/test"
width = "320" height = "100"></applet>
along with other attempts, including removing the ", trying absolute and all partial path names, and using .java, it still does not work and I end up getting a ClassNotFoundException. Other answers point out that classpath and codebase (often relating to archive) issues are a primary reason for this occurring. However, I am not using a jar file and both files are in the same directory. Anyone know why this is occurring?
Re-launch the web browser. Go to the Java applet. When the "Security Warning" window asking "Do you want to run this application?" appears, if there is a "I accept the risk and want to run this app." option, checkmark it ON first then --> Click the "Run" button. The Java applet should load OK now.
Applets are a technology that are very much of their time, and they have not aged well. The technology proved to be very difficult to evolve, and so applets have not been considered to be a modern development platform for many years now.
Java applets were deprecated by Java 9 in 2017.
No, there isn't. Java Applets are dead and there is no viable way to run them for the vast majority of users on the public Internet. If you are a software developer, you should abandon applets and start learning a modern full-stack framework. There are many to choose from.
If the class SimpleApplet
is in package test
put the HTML in the parent directory (as detailed above), and use this HTML.
<html>
<head>
<meta http-equiv="Content-Type" content"text/html; charset=utf-8">
</head>
<body>
<applet code = "test.SimpleApplet"
width = "320" height = "100"></applet>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With