• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generating a ClassLoader hierarchy for a java container  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!