Search all JARs for a class
Writing by shivdev on Wednesday, 10 of October , 2012 at 9:48 pm
If you need to search for a class (say HelloWorld) in a lib/ folder with several other jars just to see if it exists, here’s a simple command to confirm that.
find ./lib/*.jar -exec jar -tf ‘{}’ \; | grep HelloWorld.class
For a more detailed listing, you can use my findClass.sh script shown below.
#!/bin/sh # Check usage if [ $# -lt 2 ] ; then echo "Syntax: $0 <Class> <Folder>" echo "Example: $0 HelloWorld.class ./lib/a*.jar" exit 1 fi PATTERN=$1 shift FILES=$@ # Loop over files and print info for those that match for f in $FILES do LINES=`jar -tf $f | grep $PATTERN | wc -l` if [ $LINES -ge 1 ] ; then echo -e "\n\n**** Found match in:" $f " ****\n" jar -tf $f | grep $PATTERN fi done
Leave a comment
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-