dcsimg
ClassNotFoundException when deserialized from web app. Works from a standalone java program. Any ideas?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   andy_bosch
Posted On:   Tuesday, June 19, 2007 11:29 PM

Hi, Sorry for being little over descriptive here. I have an issue deserializing a file that contains a Map >. These POJO bean classes are stored in a jar file uder web-app/lib. I can deserialize the file from a standalone java program, from tomcat web app when tomcat is started from within Eclipse IDE; but I can not get it to work from the same webapp when tomcat is started in standalone mode (not from within IDE). I have some javabeans added into a List object, which is added to a LinkedHashMap object in the serialized file. This is the partial stack trace - java.lang.ClassNotFoundException: com.biz.icomp.dbi.DBCustomer at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.   More>>
			
Hi,
Sorry for being little over descriptive here. I have an issue deserializing a file that contains a Map >. These POJO bean classes are stored in a
jar file uder web-app/lib. I can deserialize the file from a standalone java program, from tomcat web app when tomcat is started from within Eclipse IDE; but
I can not get it to work from the same webapp when tomcat is started in standalone mode (not from within IDE). I have some javabeans added into a List object, which
is added to a LinkedHashMap object in the serialized file.

This is the partial stack trace -
java.lang.ClassNotFoundException: com.biz.icomp.dbi.DBCustomer
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:585)

This is the code -
FileInputStream fis = new FileInputStream(serializedFilePath);
ObjectInputStream ois = new ObjectInputStream(fis);
Map map = (Map)ois.readObject();
ois.close();

I even tried to override the default class loader as -
ClassLoader old = Thread.currentThread().getContextClassLoader();
FileInputStream fis = new FileInputStream(serializedFilePath);
ObjectInputStream ois = new ObjectInputStream(fis);
File root = new File( );
URLClassLoader urlLoader = new URLClassLoader(new URL[] { root.toURL() }, Thread.currentThread().getContextClassLoader());
Map map = (Map)ois.readObject();
ois.close();
Thread.currentThread().setContextClassLoader(old);

It still doesn't work. I also tried printing the default class loader and the loader after overriding it. This is what I see -
> When run from a standalone java class-
Default Class Loader -> sun.misc.Launcher$AppClassLoader@a39137
URLClassLoader Class Loader -> java.net.URLClassLoader@127f79d

> When run from tomcat started directly (not from IDE)-
Default Class Loader -> WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@25c828
( these last 3 lines are automatically printed )

URLClassLoader Class Loader -> java.net.URLClassLoader@170a4d0

> When run from tomcat started within Eclipse-
Default Class Loader -> WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@10d4f27


URLClassLoader Class Loader -> java.net.URLClassLoader@1ec4333

So, the class loaders are same whether or not the tomcat is started from within IDE. The class which is not found by the class loader, is actually there in a
jar file in WEB-INlib. As I said, it works when I start tomcat from eclipse. Am I missing anything? If this is a classpath issue,
I am not sure how should I resolve it. Appreciate your help.
   <<Less

Re: ClassNotFoundException when deserialized from web app. Works from a standalone java program. Any ideas?

Posted By:   Tim_Frith  
Posted On:   Wednesday, June 20, 2007 11:53 AM

Just a thought - may be way off...


Maybe there's a jar in your server that's the same one (but different version) than the one in your app. The server could be set to first try to load its own version before checking for one in your app.


Happened to me using JBoss 3.2 with commons-collections.jar.


I tried to set JBoss to look to my app for the jar before using its own, but it never worked. I ended up just updating the one in JBoss' lib dir.

About | Sitemap | Contact