How do I get a list of Java class dependencies for a main class?

dependencies, dependency-management, java

Solution

It can be eaily done with just javac. Delete your class files and then compile the main class. javac will recursively compile any classes it needs (providing you don't hide package private classes/interfaces in strangely named files). Of course, this doesn't cover any recursive hacks.

Problem

Is there a way to find all the class dependencies of a java main class? I have been manually sifting through the imports of the main class and it's imports but then realized that, because one does not have to import classes that are in the same package, I was putting together an incomplete list. I need something that will find dependencies recursively (perhaps to a defined depth).

Original source