如何在大量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。
其他回答
grep -l "classname" *.jar
告诉你罐子的名字
find . -name "*.jar" -exec jar -t -f {} \; | grep "classname"
给你类的包
#!/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
下面的脚本将帮助您
for file in *.jar
do
# do something on "$file"
echo "$file"
/usr/local/jdk/bin/jar -tvf "$file" | grep '$CLASSNAME'
done
只需使用FindClassInJars util,这是一个简单的swing程序,但很有用。您可以在http://code.google.com/p/find-class-in-jars/上查看源代码或下载jar文件
在Linux环境下,您可以执行以下操作:
$ find <base_dir> -name *.jar -print0 | xargs -0 -l jar tf | grep <name>
其中name是类文件的名称,您正在查看分布在以base_dir为根的目录层次结构中的jar中的类文件。