如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
查看JBoss Tattletale;虽然我个人从未使用过,但这似乎是你需要的工具。
其他回答
查找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"
查看JBoss Tattletale;虽然我个人从未使用过,但这似乎是你需要的工具。
下面的脚本将帮助您
for file in *.jar
do
# do something on "$file"
echo "$file"
/usr/local/jdk/bin/jar -tvf "$file" | grep '$CLASSNAME'
done
我找到了这个新方法
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。
这个在MinGW (windows bash环境)中工作得很好~ gitbash
把这个函数放到HOME目录下的.bashrc文件中:
# this function helps you to find a jar file for the class
function find_jar_of_class() {
OLD_IFS=$IFS
IFS=$'\n'
jars=( $( find -type f -name "*.jar" ) )
for i in ${jars[*]} ; do
if [ ! -z "$(jar -tvf "$i" | grep -Hsi $1)" ] ; then
echo "$i"
fi
done
IFS=$OLD_IFS
}