如何在大量jar文件中找到特定的类名?

(查找实际的类名,而不是引用它的类。)


当前回答

在eclipse中,你可以使用旧的但仍然可用的插件jarsearch

其他回答

grep -l "classname" *.jar

告诉你罐子的名字

find . -name "*.jar" -exec jar -t -f {} \; | grep  "classname"

给你类的包

你可以在一个充满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

这个在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
}

查找匹配给定字符串的jar:

找到。name \*.jar -exec grep -l YOUR_CLASSNAME {} \;

我一直在Windows上使用它,效果非常好。

findstr /s /m /c:"package/classname" *.jar, where

findstr.exe是Windows和参数的标准配置:

/s =递归 /m =如果有匹配,只打印文件名 /c =字面字符串(在这种情况下,你的包名+类名 以“/”分隔)

希望这能帮助到一些人。