如何获取主类的 Java 类依赖项列表?

有没有办法找到一个java主类的所有类依赖?

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).

推荐答案

只用 javac 就可以轻松搞定.删除你的类文件,然后编译主类.javac 将递归编译它需要的任何类(前提是您不将包私有类/接口隐藏在奇怪命名的文件中).当然,这不包括任何递归 hack.

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.

相关文章