tags:

views:

113

answers:

2

Hello, I created a simple Applet using JApplet and everything seems to work fine but as soon i create an object of my userdefined class named ChatUser in my applet, i get this error :-

SEVERE: java.lang.ClassNotFoundException: applet.ChatUser
        at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:713)
        at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:626)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at misc.ChatClient.run(ChatClient.java:43)

Any idea what can be wrong? It only happens when i create an object of any user defined class. Do i need to set some security settings or something? Please help :(

+1  A: 

It just means that the mentioned class is missing in the runtime classpath of the applet.

You do realize that applets runs at a completely different environment than where the webserver runs, namely the client machine? The client would need to download the needed libraries first. That class should be included in the applet's main JAR file or in any of the libraries referenced in the applet's archive parameter. You can specify multiple JAR's commaseparated.

<param name="archive" value="applet.jar,library1.jar,library2.jar">

This instructs the client which JAR's to download before running the applet.

BalusC
I Balusc, thanks but i already have archive set in applet tag. This is my applet tag :-<applet code="applet.chatClientApplet.class" codebase="../" archive="ChatApplet.jar" height ="400" width ="580"> <param name="userName" value="#{ChatRoomBean.userName}"/> </applet>And i get error in ChatUser class even though the jar file contains the file ChatUser in applet package
Ankit Rathod
Are the classes on the both sides exactly the same? I.e. you don't have two different classes with same package/name created in different projects? Regardless, does it contain a `private static final long serialVersionUID`? Btw, a security problem would have rather thrown an `AccessControlException`. *And now it's bedtime. I'll see this tomorrow.*
BalusC
No, i created a class library project and added all packages and classes. Then added it's reference to my web application (JSF) project. And i get this error when i run this. Btw, if i directly run applet in my class library project by clicking on file and run (in Netbeans) i still get this error. Ya, sure you see it tomorrow. Goodnight :)
Ankit Rathod
Hi BalusC, the problem got solved but i am still not satisfied.Actually i am creating ChatUser class in applet package in my class library project. And copied the same class in my ejb module in some different package (ejb module is where i am creating sockets for chatting).Now here is where the problem lies. If i copy the ChatUser class to different package then i get the exception as i have shown above. But if i copy the class to same package (applet) in my ejb module, then everything works fine. What has package got to do with all this? Does the socket check for the class in ejb module in
Ankit Rathod
same package that is there is my class library project? This is so strange. Isn't it? Waiting for your replies to clear my doubt.
Ankit Rathod
It must be *exactly* the same class and package on the both sides. This is not strange. You can have two classes with the same name in a different package (e.g. `java.util.Date` and `java.sql.Date`), but thos are not the same classes. The full class identifier covers both the package and the classname.
BalusC
A: 

It looks like a classpath problem the way you're starting the applet.

If you start the applet using NetBeans Run file, Netbeans probably takes your project classpath as classpath for the Applet and not what you've specified in the HTML page of the Applet. As you can see the classloader is com.sun.enterprise.loader.ASURLClassLoader which is not the standard classloader (URLClassLoader) that Applets use. Run your applet using the browser or the appletviewer or jnlp (Java webstart).

Anthony