Run an Applet with a package statement

Hello All;

This is very simple and I know some one out there will solve it using his left hand.

I have this very simple "Hello World" applet. if the forCounter.java file has a package statement in it

like:

package ch5.fig05_02;

// rest of the code goes here

and after I compile and get the forCounter.class file and try to launch the applet using the *.html file

which in the same directory, the applet fails to load in the browser, the error message says:

java.lang.NoClassDefFoundError: ForCounter (wrong name: ch05/fig05_02/ForCounter)

// ForCounter is the name of my class

if I removed the package statement from the *.java file and recompile the same class the applet get loaded and run perfect

here is my html file:

<html>

<applet code="ForCounter.class" width=275 height=105>

</applet>

</html>

I have the same problem with my servlets only if they are in the default package they can be run if they are part of any package I get the error

please help

[1097 byte] By [iabdel40] at [2007-9-30 4:10:43]
# 1
Try something ike this: <applet code="ch5.fig05_02.forCounter" archive="forCounter.class">
BIJ001 at 2007-6-29 17:55:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Actuall this helped me greatly with little modification, that is to but the *jar file instead of the *class file:

so the html file will be:

<html>

<applet code="ch05.fig05_01.FourCounter.class" archive="FourCounter.jar" width=275 height=105>

</applet>

</html>

Thank you

iabdel40 at 2007-6-29 17:55:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...