在几十个JAR文件中找到一个类?

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

使用 jar (或 unzip -v ), grep 和 find 命令。

例如,以下内容将列出与给定名称匹配的所有类文件:

For example, the following will list all the 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.

或使用查找(区分大小写)查找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 :

$ 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

Windows

打开命令提示符,切换到包含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命令列出所有给定存档中的文件名,并将结果写入标准输出; @ 符号禁止打印命令的调用。
  • 查找ClassName> NUL - 从jar命令的输出中搜索标准输入,用于给定的类名;如果有匹配(否则为0),这会将 ERRORLEVEL 设置为1.
  • && echo%G - iff 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).
  • 网络

    使用搜索引擎扫描 JAR文件。

    更多推荐

    在几十个JAR文件中找到一个类?

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

    发布评论

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

    >www.elefans.com

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