• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting extra class loader while using XMLDecoder  RSS feed

 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have a webapplication where i am serializing an object to XML using XMLEncoder ..The objects written to that are classes which are from the app server classpath and from jars attched by the user in some custom folder ...

But while using XMLDecoder , i need the user classes also in the current classloader so that all the classes will be read properly

I tried using Thread.currentThread().setContextClassLoader(urlLoader);

where urlloader is the loader which has loaded the User classes , but in this case its reading only user classes , not the system classes....

Can any one let me know how to read both classes using that Decoder
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sreenath reddy:
I tried using Thread.currentThread().setContextClassLoader(urlLoader);

Having had a little look at the JDK sources, it seems to me that this is the correct way to tell XMLDecoder which ClassLoader to use.
but in this case its reading only user classes , not the system classes....

I don't understand exactly what you are saying goes wrong. Can you explain carefully?

Is it possible that your "user" ClassLoader doesn't delegate properly to its parent, or doesn't have a parent? Generally, a ClassLoader should see if its parent can load the class, before trying to load it itself.
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi peter

A small mistake from my side , while creating a new URL classloader i had done a mistake by not specifying the Parent Class loader (Webapp classloader) , hence it was taking the Sun Classloader as default and was not able to load the class appropriately

Thanks a ton
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!