如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
查找匹配给定字符串的jar:
找到。name \*.jar -exec grep -l YOUR_CLASSNAME {} \;
其他回答
查找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"
不知道为什么这里的脚本从来都不适合我。如此:
#!/bin/bash
for i in *.jar; do jar -tf "$i" | grep $1 | xargs -I{} echo -e "$i : {}" ; done
在eclipse中,你可以使用旧的但仍然可用的插件jarsearch
无耻的自我推销,但你可以试试我写的实用工具:http://sourceforge.net/projects/zfind
它支持大多数常见的归档/压缩文件(jar, zip, tar, tar.gz等),不像许多其他jar/zip查找器,支持嵌套的zip文件(zip在zip, jar在jar等),直到无限的深度。
这个在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
}