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

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


当前回答

查看JBoss Tattletale;虽然我个人从未使用过,但这似乎是你需要的工具。

其他回答

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

grep -l "classname" *.jar

告诉你罐子的名字

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

给你类的包

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

下面的脚本将帮助您

for file in *.jar
do
  # do something on "$file"
  echo "$file"
  /usr/local/jdk/bin/jar -tvf "$file" | grep '$CLASSNAME'
done

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