Java 如何检查 Jar 文件之间的依赖关系?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/786708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:28:37  来源:igfitidea点击:

How To Check Dependencies Between Jar Files?

javajardependenciesredundancy

提问by Saleh Al-Zaid

I recently have taken the support and programming of a web system written in JSF. The code is kind of messy and redundant, and yes, no documentation exists.

我最近接受了用 JSF 编写的 Web 系统的支持和编程。代码有点混乱和冗余,是的,​​不存在文档。

The system has over 40 jar libraries, and most of them are redundant due to old versions and testing. To remove one jar, I must check that it's not imported in the code, so I searched the code for the jar import path (I'm using IntelliJ IDE), made sure that it's not used, and removed it.

系统有40多个jar库,其中大部分是由于版本老旧和测试造成的冗余。要删除一个 jar,我必须检查它是否未在代码中导入,因此我搜索了 jar 导入路径的代码(我使用的是 IntelliJ IDE),确保它未被使用,然后将其删除。

However, after compiling the code, a number of run-time errors occurred during testing. I figured out that I removed some jars which are used by other existing jars.

但是,在编译代码后,在测试过程中出现了许多运行时错误。我发现我删除了一些其他现有罐子使用的罐子。

The problem, how do I make sure before removing a jar that it's not used by another jar/java class?

问题是,如何在删除一个 jar 之前确保它不被另一个 jar/java 类使用?

Despite that jars have compiled classes, the compiled classes dohave the import path of required libraries. But I can't search them with IntelliJ (does not search inside jars files).

尽管 jars 有编译类,但编译后的类确实具有所需库的导入路径。但我不能用 IntelliJ 搜索它们(不在 jars 文件中搜索)。

The only way that I'm doing now is to test the system every time I remove a jar and see if I can crash it! This is totally not an easy way due to the huge number of features to be tested.

我现在正在做的唯一方法是在每次移除 jar 时测试系统,看看我是否可以使它崩溃!由于要测试的功能数量庞大,这完全不是一种简单的方法。

I wish that there is a tool where I can submit a number of java files/jars, and it displays the dependencies between them.

我希望有一个工具可以提交多个 java 文件/jar,并显示它们之间的依赖关系。

采纳答案by Uri

I know that there was a tool coming out of the JBoss project called JBoss TattleTale, might be worth taking a look:

我知道 JBoss 项目中有一个名为 JBoss TattleTale 的工具,可能值得一看:

http://www.jboss.org/tattletale

http://www.jboss.org/tattletale

回答by silmx

why don't you use Maven for your project? that will help you a lot managing dependencies.

你为什么不在你的项目中使用 Maven?这将帮助您管理依赖项。

回答by Nick Veys

JDependwill analyze dependencies for you for any number of JARs, class files, etc. Relating the packages it reports to those JARs should be a trivial extra step.

JDepend将为您分析任意数量的 JAR、类文件等的依赖关系。将它报告的包与这些 JAR 相关联应该是一个微不足道的额外步骤。

回答by giraff

I also found JarAnalyzer, but it doesn't seem to be maintained anymore.

我还找到了JarAnalyzer,但它似乎不再维护了。

回答by Anderson Mao

Well, it is year 2013 now, so I am not sure whether this tool was great on year 2009. Just used it and found it is useful: Class Dependency Analyzer(CDA) (V1.14) http://www.dependency-analyzer.org/This tool has a graph UI (Swing?). After add lib jars and Java classes, it will show the dependencies in Class/Package/Container(jar) level. It can also show the dependants as well. So it is easy to find the depend on jars and depended jars.

嗯,现在是 2013 年,所以我不确定这个工具在 2009 年是否很棒。刚刚使用它并发现它很有用: Class Dependency Analyzer(CDA) (V1.14) http://www.dependency- Analyzer.org/这个工具有一个图形用户界面(Swing?)。添加 lib jar 和 Java 类后,它将显示 Class/Package/Container(jar) 级别的依赖项。它还可以显示家属。所以很容易找到依赖的罐子和被依赖的罐子。