• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic