如何查找包含类定义的jar文件? [英] how to find the jar file containing a class definition?

查看:120
本文介绍了如何查找包含类定义的jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你最喜欢的工具,插件,脚本,是在一堆jar文件中找到一个java类吗?



很多时候我继承代码,它不存在,它只是因为jar文件不包括在类路径中。但是,在什么jar文件(s)是类?我可能没有JAR(所以我必须在线搜索),或者添加JAR到类路径可能会创建一个重复的类定义问题。



我显然更喜欢eclipse插件,但我对任何软件工作与Windows。



我知道... Windows不是我的选择,但这是我得到的使用。



谢谢!



Luis



PS谢谢你的答案。在回顾一些回应后,我意识到我应该更好地解释我的情况。我们有一个下载或创建的JAR文件库,但有时该类将在某处在线。

解决方案

(这是对我之前版本的答案的改进,以 awk 特价/丑陋的报价为代价。)



findinjars )。

 #!/ usr / bin / env bash 
if [[($#-ne 1)&& ($#-ne 2)]]
然后
echo用法是$ 0< grep模式以在'jar tvf'输出> [< top-of-dir-tree&如果缺少,当前dir]
else
THING_TO_LOOKFOR =$ 1
DIR = $ {2: - 。}
如果[! -d $ DIR];那么
echodirectory [$ DIR] does not exist;
exit 1;
fi
查找$ DIR-iname \ * .jar |同时读f; do(jar tf $ f | awk'{print'$ f'$ 0}'| grep -i$ THING_TO_LOOKFOR); done
fi

您可以使用以下方法调用它:

  $ findinjars abcdClass [directoryTreeRoot or,if missing,current dir] 

或只是

  $ findinjars partOfClassName [directoryTreeRoot or,if missing,current dir] 

完全限定类名中的点字符将被解释为任何字符的正则表达式,一个大事,因为这是一个启发式实用程序(这就是为什么它不区分大小写BTW)。通常我不打扰完整的类名,只是键入它的一部分。


What is your favorite tool, plugin, script, to find a java class in a bunch of jar files?

Very often I inherit code that complains about a class that doesn't exist, and it is just because the jar file is not included in the classpath. But, in what jar file(s) is the class? I may not have the JAR (so I have to search online), or adding a JAR to the classpath could create a duplicated class definition problem.

I obviously would prefer an eclipse plugin, but I'm open to any piece of software that works with Windows.

I know... Windows is not my choice, but that's what I got to work with.

Thanks!

Luis

P.S. Thank you for your answers. After reviewing some responses, I became aware that I should have explained better my scenario. We had a library of downloaded or created JAR files, but sometimes the class would be online somewhere.

解决方案

(This is an improvement over the script I had in previous versions of the answer as it produces much cleaner output at the price of some awk special/ugly quoting.)

I've built a script (findinjars) which does just that.

#!/usr/bin/env bash
if [[ ($# -ne 1) && ($# -ne 2) ]]
then
    echo "usage is $0 <grep pattern to look for in 'jar tvf' output> [<top-of-dir-tree> or, if missing, current dir]"
else
    THING_TO_LOOKFOR="$1"
    DIR=${2:-.}
    if [ ! -d $DIR ]; then
        echo "directory [$DIR] does not exist";
        exit 1;
    fi
    find "$DIR" -iname \*.jar | while read f ; do (jar tf $f | awk '{print "'"$f"'" "  " $0}' | grep -i "$THING_TO_LOOKFOR") ; done
fi

you can then invoke it with:

$findinjars a.b.c.d.Class [directoryTreeRoot or, if missing, current dir]

or just

$findinjars partOfClassName [directoryTreeRoot or, if missing, current dir]

Dot characters in the fully qualified class name will be interpreted in the regexp sense of 'any character' but that's not a big deal since this is a heuristics utility (that's why it's case-insensitive too BTW). Usually I don't bother with the full class name and just type part of it.

这篇关于如何查找包含类定义的jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆