aspose file tools*
The moose likes Java in General and the fly likes Get classpath for current running thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get classpath for current running thread" Watch "Get classpath for current running thread" New topic
Author

Get classpath for current running thread

Hemant B. Kumar
Greenhorn

Joined: Nov 22, 2011
Posts: 11

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

Joined: May 25, 2011
Posts: 53
Not sure if this will help you, but did you check this forum thread? Finding JVM Classes with Agent
Hemant B. Kumar
Greenhorn

Joined: Nov 22, 2011
Posts: 11

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

Joined: May 25, 2011
Posts: 53
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

Joined: Nov 22, 2011
Posts: 11

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get classpath for current running thread