DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Grep Jars For Package Or Class
Grep a bunch of jars for a certain package or class or expression:
find /path/to/directory -type f -name '*.jar' -print0 | xargs -n1 -0i sh -c 'jar tf "{}" | grep -q query && echo "{}"'
E.g.
find ~/soft/java/maven-repository -type f -name '*.jar' -print0 | xargs -n1 -0i sh -c 'jar tf "{}" | grep -q org.apache && echo "{}"'






Comments
Nicholas Sushkin replied on Thu, 2007/03/22 - 6:13pm
#!/bin/bash class=`echo $1| tr . /` shift allDirs="$(echo "$@" $CLASSPATH| perl -F: -ane 'print join(" ",@F);')" printf -- "---- Searching for %s in %s\n" "$class" "$allDirs" for dir in $allDirs; do printf -- "---- Searching in %s\n" "$dir" case $dir in *.zip) unzip -v $dir | grep $class ;; *.jar) jar -tf $dir | grep $class ;; *) find $dir -print | grep $class ;; esac done