在几十个JAR文件中找到一个类? [英] Find a class somewhere inside dozens of JAR files?
问题描述
如何在大量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 $的存档的名称c $ c>:
$ 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
- iffERRORLEVEL
非零,将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 setERRORLEVEL
to 1 iff there's a match (otherwise 0).&& echo %G
- iffERRORLEVEL
is non-zero, write the Java archive file name to standard output (the console).
网络
这篇关于在几十个JAR文件中找到一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!