如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
查看JBoss Tattletale;虽然我个人从未使用过,但这似乎是你需要的工具。
其他回答
无耻的自我推销,但你可以试试我写的实用工具:http://sourceforge.net/projects/zfind
它支持大多数常见的归档/压缩文件(jar, zip, tar, tar.gz等),不像许多其他jar/zip查找器,支持嵌套的zip文件(zip在zip, jar在jar等),直到无限的深度。
查找jar文件的脚本:find_jar.sh
IFS=$(echo -en "\n\b") # Set the field separator newline
for f in `find ${1} -iname *.jar`; do
jar -tf ${f}| grep --color $2
if [ $? == 0 ]; then
echo -n "Match found: "
echo -e "${f}\n"
fi
done
unset IFS
使用方法:./find_jar.sh <包含jar文件的顶级目录> <查找>的类名
这与这里给出的大多数答案相似。但是如果grep找到了什么,它只输出文件名。如果你想抑制grep输出,你可以重定向到/dev/null,但我更喜欢看到grep的输出,这样我就可以使用部分类名,并从显示的输出列表中找出正确的类名。
类名可以是简单类名如"String"也可以是完全限定名如"java.lang.String"
Unix
在Linux、其他Unix变体、Windows上的Git Bash或Cygwin上,使用jar(或unzip -v)、grep和find命令。
下面列出了与给定名称匹配的所有类文件:
for i in *.jar; do jar -tvf "$i" | grep -Hsi ClassName && echo "$i"; done
如果知道要搜索的整个Java存档列表,可以使用(符号)链接将它们全部放在同一个目录中。
或者使用find(区分大小写)查找包含给定类名的JAR文件:
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命令可用:
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文件的目录(或祖先目录),然后:
for /R %G in (*.jar) do @jar -tvf "%G" | find "ClassName" > NUL && echo %G
下面是它的工作原理:
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).
Web
使用扫描JAR文件的搜索引擎。
我一直在Windows上使用它,效果非常好。
findstr /s /m /c:"package/classname" *.jar, where
findstr.exe是Windows和参数的标准配置:
/s =递归 /m =如果有匹配,只打印文件名 /c =字面字符串(在这种情况下,你的包名+类名 以“/”分隔)
希望这能帮助到一些人。
ClassFinder是一个专门用来解决这个问题的程序。它允许您在目录和jar文件中递归搜索,以找到与模式匹配的类的所有实例。它是用Java编写的,而不是python。它有一个很好的图形用户界面,这使得它易于使用。它跑得很快。这个版本是在一个可运行的jar中预编译的,所以您不必从源代码构建它。
在这里下载:ClassFinder 1.0