Skip to content

Instantly share code, notes, and snippets.

@mononite
Created August 6, 2013 06:36
Show Gist options
  • Save mononite/6162548 to your computer and use it in GitHub Desktop.
Save mononite/6162548 to your computer and use it in GitHub Desktop.
A script which is used to find class or package by name from jar files.
#!/bin/bash
# usage: jargrep.sh <name> [path ...], name can be package name or class name
# example: jargrep.sh org.apache.commons, jargrep.sh TypeSafeMatcher ~/.m2
# The minimum size of a zip file is 22 bytes. http://en.wikipedia.org/wiki/Zip_(file_format)
if [ $# -lt 1 ]; then
echo "Usage: $0 name [path ...]";
exit 2;
fi
name=${1//./\/};
shift;
path=${@:-.};
function check-jar() {
jar -tf "$1" | grep -iH --label "$1" "$name";
}
status=1;
while read -r -d '' jarfile; do
check-jar "$jarfile" && status=0;
done < <(find $path -type f -name '*.jar' -size +22c -print0)
exit $status;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment