/ Published in: Bash
Find class or resource in jar files and/or directories of jars/zips.
Expand |
Embed | Plain Text
#! /bin/bash function usage { echo 'Find class or resource in jar files and/or directories of jars.' echo '' echo 'usage: $0 pattern files... dirs...' echo '' exit } function fqcn2path { fqcn=$1 path=`echo $fqcn | sed -e 's@\.@/@g'` echo $path } target=/usr/java/jdk/jre/lib/rt.jar pattern= quiet= while getopts e:q c do case $c in 'q') quiet=t ; break ;; '?') # any other switch usage ;; esac done shift `expr $OPTIND - 1` if [ $# -eq 0 ] ; then usage fi pattern=`fqcn2path "$1"` shift 1 if [ $# -gt 0 ] ; then target=$* fi declare cygwin="" case "`uname -o`" in Cygwin*) cygwin=true ;; *) ;; esac function look { if [ "$quiet" = "" ] ; then echo $1 . . fi if [ -n "$cygwin" ] ; then p="`cygpath -wa $1`" else p="$1" fi if [ -r $1 ] ; then if [ "$pattern" == "" ] ; then jar tvf "$p" else jar tvf "$p" | fgrep $pattern fi else echo ERROR: Cannot read $1 fi } for t in $target do if [ -d $t ] ; then for f in `find $t -type f -name "*.jar" -o -name "*.zip"` do look $f done else look $t fi done
Comments
Subscribe to comments
You need to login to post a comment.

Also works with Cygwin on Windows
Find class or resource in jar files and/or directories of jars/zips.
Usage: class.sh pattern files..