Thursday, February 19, 2009

Searching classes inside jars

Do you want to find the jar name containing a particular class from the set of jars in an environment or folder. Here is the same code for you which you can use in your linux environment.

Save the below code as sample.sh

////////////Code////////////

find . -name '*.jar' | while read file
do
  echo "[*] Listing coincidences into ${file}:"
  echo "==================="
  unzip -l "$file" | grep "Enter class name here to search"
done

//////////Code//////////////

Replace the string "Enter class name here to search" with the class name which you are searching for from the present working directory.

Execute the sample.sh and you will get the jar name listing one by one. If your class name is present then it will list your class name along with jar.