在几十个 JAR 文件中的某个地方找到一个类? [英] Find a class somewhere inside dozens of JAR files?

查看:38
本文介绍了在几十个 JAR 文件中的某个地方找到一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在大量 jar 文件中找到特定的类名?

How would you find a particular class name inside lots of jar files?

(寻找实际的类名,而不是引用它的类.)

(Looking for the actual class name, not the classes that reference it.)

推荐答案

Unix

在 Linux、其他 Unix 变体、Windows 上的 Git Bash 或 Cygwin 上,使用 jar(或 unzip -v)、grep, 和 find 命令.

Unix

On Linux, other Unix variants, Git Bash on Windows, or Cygwin, use the jar (or unzip -v), grep, and find commands.

以下列出了与给定名称匹配的所有类文件:

The following lists all class files that match a given name:

for i in *.jar; do jar -tvf "$i" | grep -Hsi ClassName && echo "$i"; done

如果您知道要搜索的 Java 档案的完整列表,您可以使用(符号)链接将它们全部放在同一目录中.

If you know the entire list of Java archives you want to search, you could place them all in the same directory using (symbolic) links.

或者使用find(区分大小写)查找包含给定类名的JAR文件:

Or use find (case sensitively) to find the JAR file that contains a given class name:

find path/to/libs -name '*.jar' -exec grep -Hls ClassName {} ;

例如,要查找包含 IdentityHashingStrategy 的存档名称:

For example, to find the name of the archive containing IdentityHashingStrategy:

$ find . -name '*.jar' -exec grep -Hsli IdentityHashingStrategy {} ;
./trove-3.0.3.jar

如果 JAR 可以在系统中任何地方并且 locate 命令可用:

If the JAR could be anywhere in the system and the locate command is available:

for i in $(locate "*.jar");
  do echo "$i"; jar -tvf "$i" | grep -Hsi ClassName;
done

语法变体:

find path/to/libs -name '*.jar' -print | 
  while read i; do jar -tvf "$i" | grep -Hsi ClassName && echo "$i"; done 

视窗

打开命令提示符,切换到包含 JAR 文件的目录(或祖先目录),然后:

Windows

Open a command prompt, change to the directory (or ancestor directory) containing the JAR files, then:

for /R %G in (*.jar) do @jar -tvf "%G" | find "ClassName" > NUL && echo %G

这是它的工作原理:

  1. for/R %G in (*.jar) do - 循环遍历所有 JAR 文件,递归遍历目录;将文件名存储在 %G 中.
  2. @jar -tvf "%G" | - 运行 Java Archive 命令以列出给定存档中的所有文件名,并将结果写入标准输出;@ 符号禁止打印命令的调用.
  3. 找到类名">NUL - 搜索标准输入,从 jar 命令的输出通过管道输入给定的类名;如果匹配,这会将 ERRORLEVEL 设置为 1(否则为 0).
  4. <代码>&&echo %G - 如果 ERRORLEVEL 非零,则将 Java 存档文件名写入标准输出(控制台).
  1. for /R %G in (*.jar) do - loop over all JAR files, recursively traversing directories; store the file name in %G.
  2. @jar -tvf "%G" | - run the Java Archive command to list all file names within the given archive, and write the results to standard output; the @ symbol suppresses printing the command's invocation.
  3. find "ClassName" > NUL - search standard input, piped from the output of the jar command, for the given class name; this will set ERRORLEVEL to 1 iff there's a match (otherwise 0).
  4. && echo %G - iff ERRORLEVEL is non-zero, write the Java archive file name to standard output (the console).

网页

使用扫描搜索引擎://www.findjar.com/" rel="noreferrer">JAR 文件.

Web

Use a search engine that scans JAR files.

这篇关于在几十个 JAR 文件中的某个地方找到一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆