如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
我找到了这个新方法
bash $ ls -1 | xargs -i -t jar -tvf '{}'| grep Abstract
jar -tvf activation-1.1.jar
jar -tvf antisamy-1.4.3.jar
2263 Thu Jan 13 21:38:10 IST 2011 org/owasp/validator/html/scan/AbstractAntiSamyScanner.class
...
如果你想,你可以给ls -1 *.jar,或者用查找命令HTH Someone输入xargs。
其他回答
#!/bin/bash
pattern=$1
shift
for jar in $(find $* -type f -name "*.jar")
do
match=`jar -tvf $jar | grep $pattern`
if [ ! -z "$match" ]
then
echo "Found in: $jar"
echo "$match"
fi
done
查找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"
你可以在一个充满jar的目录中找到一个类,它带有一些shell:
寻找类“FooBar”:
LIB_DIR=/some/dir/full/of/jarfiles
for jarfile in $(find $LIBDIR -name "*.jar"); do
echo "--------$jarfile---------------"
jar -tvf $jarfile | grep FooBar
done
grep -l "classname" *.jar
告诉你罐子的名字
find . -name "*.jar" -exec jar -t -f {} \; | grep "classname"
给你类的包
我一直在Windows上使用它,效果非常好。
findstr /s /m /c:"package/classname" *.jar, where
findstr.exe是Windows和参数的标准配置:
/s =递归 /m =如果有匹配,只打印文件名 /c =字面字符串(在这种情况下,你的包名+类名 以“/”分隔)
希望这能帮助到一些人。