eclipse 如何在一堆罐子中找到类名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7567887/
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-09-10 20:34:04  来源:igfitidea点击:

How to find class name inside a bunch of jars

eclipse

提问by Pawan

I have a whole lot of jar files in my system , related to my Application .

我的系统中有很多 jar 文件,与我的应用程序相关。

How can i find a particular class in that whole lot of jar files ??

我怎样才能在一大堆 jar 文件中找到一个特定的类?

Thank you

谢谢

回答by Thilo

If those jar files are in the build path of your Eclipse project:

如果这些 jar 文件位于 Eclipse 项目的构建路径中:

Ctrl-Shift-T (for "Open Type", "type" as in "class") brings up a search box. You can CamelType (i.e. SB instead of StringBuilder).

Ctrl-Shift-T(对于“Open Type”,“type”如“class”)会调出一个搜索框。您可以使用 CamelType(即 SB 而不是 StringBuilder)。

回答by D.Shawley

You should be able to right-click on the class name in a source file and select one of the sub-items of the Declarationscontext menu item - i.e., right click on the class name and select Declarations/Project. This will search the project for any declarations of the class and pop up the standard Eclipse search results view. I am assuming that you have the jar as a library in your Eclipse project.

您应该能够右键单击源文件中的类名并选择Declarations上下文菜单项的子项之一- 即右键单击类名并选择Declarations/ Project。这将在项目中搜索该类的任何声明并弹出标准的 Eclipse 搜索结果视图。我假设您将 jar 作为 Eclipse 项目中的库。

If you want to do this on the file system instead, then use a for loop to iterate over the JAR files and use jar tf FILENAMEto get the list of class files and pipe that through grepor findstr(depending on your platform). If you are using bash, something like the following would do the trick:

如果您想在文件系统上执行此操作,则使用 for 循环遍历 JAR 文件并用于jar tf FILENAME获取类文件列表并通过管道将其通过grepor findstr(取决于您的平台)。如果您正在使用bash,则类似以下内容可以解决问题:

bash-3.2$ for f in *.jar
do
  result=$(jar tf $f | grep '/DBObject.class$')
  [ -n "$result" ] && echo "$f contains $result"
done
mongodb-api-2.6.3.jar contains com/mongodb/DBObject.class
bash-3.2$ 

You could concoct something similar in Windows using a FORloop at a command prompt but I don't recall if FINDSTRsets the result ERRORLEVELcorrectly. The following should work not completely sure of the syntax:

您可以FOR在命令提示符下使用循环在 Windows 中炮制类似的东西,但我不记得是否正确FINDSTR设置了结果ERRORLEVEL。以下应该工作不完全确定语法:

C:\Directory\Containing\Jars> FOR %I IN (*.jar) DO @(
  FOR /F %J IN ('jar tf %I') DO ECHO "%J: %I"
) | FINDSTR /R /C:"/DBObject.class$"
mongodb-api-2.6.3.jar: com/mongodb/DBObject.class
C:\Directory\Containing\Jars>

If I remember, I'll edit this after I get to a Windows machine.

如果我记得的话,我会在使用 Windows 机器后对其进行编辑。