• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Setting extra class loader while using XMLDecoder

 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic