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.