#!/bin/bash

if [ "$#" -eq 0 ]
then
    echo
    echo "Search recursevily through directory containing JAR files for filenames inside JARs"
    echo "Usage: $0 <filename_or_path_or_part_of_it> [<directory_path_to_search>]"
    echo "Example: $0 com/sun/xml/ws/spi/ProviderImpl /opt/oracle/app/Middleware/"
    echo
    exit 
fi

searchdir="/opt/oracle/app/Middleware/wlserver_10.3/server/lib/"
if [ "$#" -eq 2 ]
then
    searchdir=$2
fi

mismatched=0
echo
echo "Searching filename $1 from $searchdir :"
echo

for i in `find $searchdir -type f -name '*.jar'`;
do
    res=`jar tf $i 2>/dev/null | grep $1`
    if [[ $res != "" ]]
    then
      echo -en "\r_____________________________________________________________________"
      echo
      echo $i
      echo
      echo "$res"
      echo
    else
	mismatched=$[$mismatched+1]
	echo -en "\rMismatched JARs: $mismatched"
    fi
done   

echo
