I am looking for a tool that lists the .class dependencies for a given Java class to run. Kind of like what Dependency Walker does for Windows applications.
I am aware of some tools, but they are overly complicated or not quite a match, including
Any suggestions? TIA!!
The JVM will only load classes that are actually referenced in the program. Therefore, you will probably not be able to reduce runtime memory consumption by pruning the dependencies. If you are after reducing program size to ease deployment though, you can use this to detect which classes are actually needed: Simply run the application with the VM’s class loading logging enabled, and the logfile will list all used classes.
For instance, for the Sun JVM, you would add the VM parameter
-verbose:class, i.e. launch your application as follows:and postprocess the log to extract all class names.
(Of course this approach assumes the same classes are used for each execution of the program, which is probably the case for your “simple CLI utility”)