如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
下面的脚本将帮助您
for file in *.jar
do
# do something on "$file"
echo "$file"
/usr/local/jdk/bin/jar -tvf "$file" | grep '$CLASSNAME'
done
其他回答
在eclipse中,你可以使用旧的但仍然可用的插件jarsearch
查找匹配给定字符串的jar:
找到。name \*.jar -exec grep -l YOUR_CLASSNAME {} \;
在Linux环境下,您可以执行以下操作:
$ find <base_dir> -name *.jar -print0 | xargs -0 -l jar tf | grep <name>
其中name是类文件的名称,您正在查看分布在以base_dir为根的目录层次结构中的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"
这个在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
}