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

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


当前回答

我知道这是个老问题,但是…… 我也有同样的问题,所以如果有人正在寻找一个非常简单的解决方案的windows -有一个软件名为Locate32 只要把jar作为文件扩展名 并包含类名 它会在几秒钟内找到文件。

其他回答

#!/bin/bash

pattern=$1
shift

for jar in $(find $* -type f -name "*.jar")
do
  match=`jar -tvf $jar | grep $pattern`
  if [ ! -z "$match" ]
  then
    echo "Found in: $jar"
    echo "$match"
  fi
done

你可以使用locate和grep:

locate jar | xargs grep 'my.class'

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

下面的脚本将帮助您

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

使用unzip (zipinfo)的bash脚本解决方案。在Ubuntu 12上测试。

#!/bin/bash

# ./jarwalker.sh "/a/Starting/Path" "aClassName"

IFS=$'\n'
jars=( $( find -P "$1" -type f -name "*.jar" ) )

for jar in ${jars[*]}
    do
        classes=( $( zipinfo -1 ${jar} | awk -F '/' '{print $NF}' | grep .class | awk -F '.' '{print $1}' ) )
        if [ ${#classes[*]} -ge 0 ]; then
            for class in ${classes[*]}
                do
                    if [ ${class} == "$2" ]; then
                        echo "Found in ${jar}"
                    fi
                done
        fi
    done

检查这个eclipse插件,它可以做你正在寻找的工作。

https://marketplace.eclipse.org/content/jarchiveexplorer