你如何弄清楚哪些JAR依赖于哪一个?

时间:2021-03-08 21:10:48

I've trying to use Eclipse JDT AST parsing classes. After including the initial JAR, and sorting out a couple more dependencies, it is with 7+ JARs and I still having NoClassDefFoundError exceptions. This situation arises whenever I'm trying to test libraries with little or no documentation. Trial and error seems a very dumb (and annoying) approach to solve this problem.

我试图使用Eclipse JDT AST解析类。在包含初始JAR并整理出更多依赖项之后,它有7个以上的JAR并且我仍然有NoClassDefFoundError异常。每当我尝试使用很少或没有文档来测试库时,就会出现这种情况。试验和错误似乎是一种非常愚蠢(和讨厌)的方法来解决这个问题。

Is there a way to automatically sort this out using Eclipse?

有没有办法使用Eclipse自动排序?


Update: Later I found that adding all the JARs you have, and using Ctrl-T (to view/locate types), lets you manually locate the JAR. That was the solution that Google provided so far. Is there a better way?

更新:后来我发现添加所有JAR,并使用Ctrl-T(查看/定位类型),可以手动找到JAR。这是Google迄今为止提供的解决方案。有没有更好的办法?

3 个解决方案

#1


If you refer to this SO question Finding unused jars used in an eclipse project, you also have:

如果你参考这个SO问题找到eclipse项目中使用的未使用的jar,你还有:

ClassPathHelper, which can quickly focus on unresolved classes:

ClassPathHelper,可以快速关注未解析的类:

你如何弄清楚哪些JAR依赖于哪一个?

It automatically identifies orphan jars, blocked (obscured) classes, and much more.

它会自动识别孤立的jar,阻塞(模糊)类等等。

The only limit is dependencies that are not defined in classes, e.g. in dependency injection framework configuration files.

唯一的限制是未在类中定义的依赖关系,例如在依赖注入框架配置文件中。

#2


I have found setting up a workspace exclusively for browsing the eclipse source code incredibly useful. In this manner, you can use PDE tools like the Plug-in Spy, bundle dependency analysis, browsing the documentation, etc much like you would your own plugin projects. I found this article at Vogella a very useful guide.

我发现专门设置一个工作区来浏览eclipse源代码非常有用。通过这种方式,您可以使用PDE工具,如插件间谍,捆绑依赖性分析,浏览文档等,就像您自己的插件项目一样。我在Vogella发现这篇文章非常有用。

If you know which bundle your desired class is you can generate the transitive closure of dependencies by creating a new OSGi launch configuration, with just the single bundle selected. By hitting the Add Required button, you can see all bundles necessary to use the one you're interested in.

如果您知道所需类的哪个包,则可以通过创建新的OSGi启动配置来生成依赖项的传递闭包,只选择单个包。通过点击Add Required按钮,您可以看到使用您感兴趣的所有捆绑包。

Edit:

  • From your question it wasn't clear as to the environment you want to run the compiler in. If you're interested in an embeddable Java compiler to be run outside of an OSGi environment, may I suggest Janino.
  • 从你的问题来看,你想要运行编译器的环境还不清楚。如果你对可嵌入的Java编译器感兴趣在OSGi环境之外运行,我可以建议Janino。

#3


You could use a dependency analyzer like: JarAnalyzer

您可以使用依赖性分析器,如:JarAnalyzer

This will parse a directory full of Jars and give you an XML output dependency map, for which there are several tools for displaying in either graphical or text form.

这将解析一个充满Jars的目录,并为您提供一个XML输出依赖关系图,其中有几个工具可以以图形或文本形式显示。

#1


If you refer to this SO question Finding unused jars used in an eclipse project, you also have:

如果你参考这个SO问题找到eclipse项目中使用的未使用的jar,你还有:

ClassPathHelper, which can quickly focus on unresolved classes:

ClassPathHelper,可以快速关注未解析的类:

你如何弄清楚哪些JAR依赖于哪一个?

It automatically identifies orphan jars, blocked (obscured) classes, and much more.

它会自动识别孤立的jar,阻塞(模糊)类等等。

The only limit is dependencies that are not defined in classes, e.g. in dependency injection framework configuration files.

唯一的限制是未在类中定义的依赖关系,例如在依赖注入框架配置文件中。

#2


I have found setting up a workspace exclusively for browsing the eclipse source code incredibly useful. In this manner, you can use PDE tools like the Plug-in Spy, bundle dependency analysis, browsing the documentation, etc much like you would your own plugin projects. I found this article at Vogella a very useful guide.

我发现专门设置一个工作区来浏览eclipse源代码非常有用。通过这种方式,您可以使用PDE工具,如插件间谍,捆绑依赖性分析,浏览文档等,就像您自己的插件项目一样。我在Vogella发现这篇文章非常有用。

If you know which bundle your desired class is you can generate the transitive closure of dependencies by creating a new OSGi launch configuration, with just the single bundle selected. By hitting the Add Required button, you can see all bundles necessary to use the one you're interested in.

如果您知道所需类的哪个包,则可以通过创建新的OSGi启动配置来生成依赖项的传递闭包,只选择单个包。通过点击Add Required按钮,您可以看到使用您感兴趣的所有捆绑包。

Edit:

  • From your question it wasn't clear as to the environment you want to run the compiler in. If you're interested in an embeddable Java compiler to be run outside of an OSGi environment, may I suggest Janino.
  • 从你的问题来看,你想要运行编译器的环境还不清楚。如果你对可嵌入的Java编译器感兴趣在OSGi环境之外运行,我可以建议Janino。

#3


You could use a dependency analyzer like: JarAnalyzer

您可以使用依赖性分析器,如:JarAnalyzer

This will parse a directory full of Jars and give you an XML output dependency map, for which there are several tools for displaying in either graphical or text form.

这将解析一个充满Jars的目录,并为您提供一个XML输出依赖关系图,其中有几个工具可以以图形或文本形式显示。