Search code examples
javaappletclassnotfoundexception

Applet on Website seems to hate Packages


So I made an Applet (not JApplet) and proceeded to upload it to my website. I put all of my .class files into a package, exported the project from eclipse to a .jar, and uploaded that to the public_html folder of my website.

In my HTML code, I put

<applet ARCHIVE="BallShooter.jar" CODE="BallShooter" width=500 height=500> </applet>

However, it seems that I kept on getting the error "ClassNotFoundException" If I reupload the .jar WITHOUT the package, it worked fine. Could somebody please explain to me how to fix this?

For those who are wondering, this is the structure of the things in the website

/public_html/myAppletJar/myPackage/a.class  
/public_html/myAppletJar/myPackage/b.class  
/public_html/myAppletJar/a.png  
/public_html/myAppletJar/b.png  

Solution

  • Check all these points:

    • if the applet class is BallShooter, and is in the package kikiotsuka, then its source code must start with the line package kikiotsuka;. The full name of the class is thus kikiotsuka.BallShooter.
    • in the jar file, you should thus have a directory named kikiotsuka at the root, and this directory must contain a file named BallShooter.class
    • since the name of the class is kikiotsuka.BallShooter, that's what the code attribute of the applet HTML element must contain: code="kikiotsuka.BallShooter" width=...