在几十个 JAR 文件中的某个地方找到一个类?

编程入门 行业动态 更新时间:2024-10-08 13:34:10
本文介绍了在几十个 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

这是它的工作原理:

  • for/R %G in (*.jar) do - 循环遍历所有 JAR 文件,递归遍历目录;将文件名存储在 %G 中.
  • @jar -tvf "%G" | - 运行 Java Archive 命令以列出给定存档中的所有文件名,并将结果写入标准输出;@ 符号禁止打印命令的调用.
  • 找到类名">NUL - 搜索标准输入,从 jar 命令的输出通过管道输入给定的类名;如果匹配,这会将 ERRORLEVEL 设置为 1(否则为 0).
  • &&echo %G - 如果 ERRORLEVEL 非零,则将 Java 存档文件名写入标准输出(控制台).
  • for /R %G in (*.jar) do - loop over all JAR files, recursively traversing directories; store the file name in %G.
  • @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.
  • 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).
  • && echo %G - iff ERRORLEVEL is non-zero, write the Java archive file name to standard output (the console).
  • 网页

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

    Web

    Use a search engine that scans JAR files.

    更多推荐

    在几十个 JAR 文件中的某个地方找到一个类?

    本文发布于:2023-11-29 09:27:39,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1646005.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:几十个   文件   地方   JAR

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!