Reputation: 526
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)?
Upvotes: 14
Views: 14315
Reputation: 262494
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.
Upvotes: 3
Reputation: 3155
There exist a couple of techniques to debug classloading problems. Here are good slides from the JRebel creators summarizing those techniques: Do you really get class loaders?
Upvotes: 1
Reputation: 6251
You could use InTrace to instrument the Classloader classes which do the loading.
For the Sun JVM, I would suggest using the following Include patterns to trace appropriate classes:
Upvotes: 2
Reputation: 1842
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.
Upvotes: 1
Reputation: 147154
Resources are provided as URL
s. So, I guess to do it in "pure" Java: Install a custom ClassLoader
that copies URL
s into a version with a custom URLStreamHandler
. Put your monitoring code in the stream handler and forward to the original.
Upvotes: 2