views:

521

answers:

3

Hi everybody, this is my first question here in stackoverflow (and I hope not the last one :P).

To debug class loading in a JVM we can use the param -verbose:class, but... Anyone knows how to debug resources loading (e.g. properties files)?

Thank you in advance!

+1  A: 

I suppose you need to look at using a profiler. Or something that uses the instrumentation interface.

Not sure how stable it is, but there is BTrace, which is kind of a Java version of DTrace.

BTrace is a safe, dynamic tracing tool for the Java platform. BTrace can be used to dynamically trace a running Java program. BTrace dynamically instruments the classes of the target application to inject tracing code ("bytecode tracing"). Tracing code is expressed in Java programming language.

If you are doing this on a development machine, and the number of events (resources being loaded) is not too frequent, you could also just set a breakpoint in the debugger.

Thilo
+2  A: 

Resources are provided as URLs. So, I guess to do it in "pure" Java: Install a custom ClassLoader that copies URLs into a version with a custom URLStreamHandler. Put your monitoring code in the stream handler and forward to the original.

Tom Hawtin - tackline
+1  A: 

In a Linux environment you can try:

lsof -p <jvm pid>

It will give you a list with the descriptors used by the program associated with the specified pid.

More Info

Daniel H.
The problem is that many resources can be loaded from a single jar file, which might only be opened one time.
erickson
I agree, in that case I think the best option is to go with the ClassLoader solution
Daniel H.