• 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
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Generating a ClassLoader hierarchy for a java container

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm currently writing an java app running on top of an OSGi container.

What I want to do is to be able to enumerate ALL classloaders running on the container and to visualize the classloader hierachy. My question is: how do I go about doing this? I can obviously obtain the system classloader easily e.g. System.getSystemClassLoader(). From what I understand, classloaders at the top of the inverted tree cannot walk the tree since they don't know about their children (that is, only children classloaders know of their parent).

Thanks for any ideas.

Regards,

Pho
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classloading hierarchy is something specific to container implementation.
The way Tomcat does the same might be different from the way its done for some other container .Nor I am aware of any means by which you can find the exact classloading hierarchy for your container.

The best place to look for this would be the documentation of that container.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you can get get the parent CL of a CL, start at the bottom, i.e. by getClass.getClassLoader. That will only give you part of the hierarchy, of course.
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this visualization of the classloader hierachy in OSGi. The picture is taken from this presentation.

Basically if I contributed a bundle into the OSGi container, and do what Ulf suggested, I'm looking at one tree path.

I am able to get an array of running bundles in the container (via the OSGi APIs) and the Bundle class offers this method:



Obviously this poses the question: how do I know what classes are in each bundle ?

Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic