Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get classpath for current running thread

 
Hemant B. Kumar
Greenhorn
Posts: 11
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to find out what all jars/directories present in the classpath(including classpaths of parent class loaders) while executing a class. Please suggest a way.
I tried below -

But it has a limitation as it would work only if all the class loaders in the hierarchy extends URLClassLoader, which I suppose cant be assumed.
Please share your thoughts.

-Hemant
 
Alvin Watkins
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this will help you, but did you check this forum thread? Finding JVM Classes with Agent
 
Hemant B. Kumar
Greenhorn
Posts: 11
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alvin for pointing to a nice discussion thread.
But I could not find a direct method in Instrumentation interface which could give me the list of Jars in Classpath. Only thing that I could see is some methods listing the classes already initialized/loaded.
 
Alvin Watkins
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see.

Could you use System.getProperty("java.class.path") and then use a File[] to find all the jars there?
 
Hemant B. Kumar
Greenhorn
Posts: 11
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.getProperty("java.class.path")


This returns the classpath of just the System class loader. It does not even list the JRE extension jars.
Consider an application running on a J2EE application server, where we will have classloader hierarchy extending the System Classloader.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic