在数百个已编译的 jar 中查找方法或符号调用

Find method or symbol call in hundreds of compiled jars

我花了最后一个小时寻找一种简单的方法来在数百个已编译的 jar 中查找符号和方法调用。我试图将它们全部加载到 ide 中以使用搜索符号功能,但 ide 只索引在 public 上设置的那些而不是调用。 你能想出一种不包括一个接一个地反编译 jar 的简单方法吗?我有点不得不经常用不同的罐子来做这件事。

我将不胜感激任何 ide,因为这可以让我更进一步。感谢您的宝贵时间。

运行 javap 对抗每个罐子中的每个 class。

我会使用 unix“find”命令对给定目录中的每个 jar 文件应用复杂的 unzip-pipeline-into-javap:

find -iname \*.jar -execdir bash -c "

  unzip -qql {}       | # -l to list zip contents, and -qq to keep quiet.
    sed 's/  */ /g'   | # convert groups of spaces to a single space
    cut -d ' ' -f 5   | # pull out 5th field of each unzip output line
    grep '.class$'    | # each line must end in ".class"
    sed 's/.class$//' | # convert to java class name: remove trailing ".class"
    tr '/' '.'        | # convert to java class name: convert '/' to '.'
    sort              | # sort classnames
  #
  # And, finally, call 'javap' against each class, with most options enabled:
  #
  xargs /opt/java/jdk1.8.0_25/bin/javap -s -p -v -l -c  -cp {}

" \; | gzip > every-jar-decompiled.txt.gz

在我的测试中输出非常重要(对于 100MB 的罐子超过 1GB),我将其 gzip 压缩。使用“zcat”或“zgrep”检查结果。

如果您使用 windows,您可能可以使用 cygwin 到 运行 这个命令。