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

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


当前回答

在Linux环境下,您可以执行以下操作:

$ find <base_dir> -name *.jar -print0 | xargs -0 -l jar tf | grep <name>

其中name是类文件的名称,您正在查看分布在以base_dir为根的目录层次结构中的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
}

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

除此之外,还有一件事需要补充:如果您没有可用的jar可执行文件(它随JDK而不是JRE一起提供),您可以使用unzip(或WinZip或其他任何工具)来完成同样的事情。

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

你可以使用locate和grep:

locate jar | xargs grep 'my.class'

确保在使用locate之前运行updatedb。