how to find the jar file containing a class definition? [closed] how to find the jar file containing a class definition? [closed] windows windows

how to find the jar file containing a class definition? [closed]


(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 bashif [[ ($# -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") ; donefi

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.


In the same lines as BalusC's answer (I can't post comment yet nor link 2 urls, no reputation :( ), you can find a jar thanks to these 2 jar finder engines:- http://www.jarfinder.com/ - findjar


A simpler command. You don't have to use 'while-do', use '&&' to print file name if 'grep' finds the class.

find . -name '*.jar' -print0 |  xargs -0 -I '{}' sh -c 'jar tf {} | grep Hello.class &&  echo {}'