如何获取主类的 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能想看看
jdeps
命令行工具:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html
该命令将返回该 java 类的依赖项列表文件。 您可以在命令中使用许多其他选项,例如
-regex
来查找与给定模式匹配的依赖项You may want to take a look at the
jdeps
command line tool:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html
The command will return a list of the dependencies for that java class file. There are many other options that you can use in your command like
-regex
to find dependencies matching a given pattern我刚刚找到 类依赖分析器,下载、安装配置,10 分钟后我就有了完整的类依赖项列表。
I just found Class Dependency Analyzer, download, install configure and 10 min's later I have a complete class Dependency list.
只需javac即可轻松完成。 删除您的类文件,然后编译主类。 javac 将递归编译它需要的任何类(前提是您没有在奇怪命名的文件中隐藏包私有类/接口)。 当然,这不包括任何递归黑客。
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.
在intellij idea中,你有一个漂亮的依赖结构矩阵。 您可以完美地探索包级和类级依赖关系。 如果你喜欢简单一点,你也有一个依赖关系查看器,但在那里你只能看到一阶依赖关系。
in intellij idea you have the nifty dependency structure matrix. you can explore package- and class-level dependencies perfectly. if you like it simpler, you have a dependency viewer as well, but htere you can only see first-order dependencies.
下面是一个代码片段,您可以将其放入 Java 的 main 方法中,以输出应用程序所有依赖项的路径:
Here is a code snippet you can put into your main method in Java to output paths to all dependencies of your application: