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

发布于 2024-07-07 09:27:02 字数 134 浏览 9 评论 0原文

有没有办法找到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

听风念你 2024-07-14 09:27:02

您可能想看看jdeps命令行工具:

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html

jdeps -cp <your cp> -v <path to your .class file>

该命令将返回该 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

jdeps -cp <your cp> -v <path to your .class file>

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

婴鹅 2024-07-14 09:27:02

我刚刚找到 类依赖分析器,下载、安装配置,10 分钟后我就有了完整的类依赖项列表。

I just found Class Dependency Analyzer, download, install configure and 10 min's later I have a complete class Dependency list.

自演自醉 2024-07-14 09:27:02

只需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.

我是男神闪亮亮 2024-07-14 09:27:02

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.

甜味拾荒者 2024-07-14 09:27:02

下面是一个代码片段,您可以将其放入 Java 的 main 方法中,以输出应用程序所有依赖项的路径:

ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
for(URL url: urls){
    System.out.println(url.getPath());
}

Here is a code snippet you can put into your main method in Java to output paths to all dependencies of your application:

ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
for(URL url: urls){
    System.out.println(url.getPath());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文