• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 43028
76
  • 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
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic