Thursday, November 11, 2004

Search through jars for a class, then invoke javap

Script now works nicely--now to track down my DOM problem:
#!/bin/bash
temp='./temp.out'
temp2='./temp2.out'

echo -n "Enter class name: "
read -e SEARCHEE
echo Beginning recursive search through jars $PWD for $SEARCHEE
for i in `find . -name "*.jar"`;
do
# result= sed -e 's/\//\./g `jar tf $i | grep -i $SEARCHEE`'
result=`jar tf $i | grep -i $SEARCHEE`
if [ "$result" != "" ]; then
echo $result > $temp
#replace / to .
result=`sed 's/\//./g' $temp`
echo $result > $temp
#get rid of the .class, print to file for awk evaluation
`sed 's/.class/\ /' $temp > $temp2`
result=`awk 'BEGIN {FS="[ ]"}; { print $1 }' $temp2`
echo $i
echo $result
#setting the bootclasspath to . otherwise this search
#will report classes found in the bootclasspath jars and not the
#jars starting in .
javap -classpath $i $result -bootclasspath .
`rm $temp`
`rm $temp2`
echo
fi
done

No comments: