Script for finding a class inside a directory of JARs

15 Jun 2009

In the spirit of automating anything I've done more than twice manually, here's an incredibly simple yet useful little script to recursively search a tree of JARs for a class file. I most often use this against a local Maven repository.

[bash] #!/bin/sh #Example Usages: # findjars com/ambientideas/SuperWidget # findjars AnotherWidget CLASSNAMETOFIND="$1" echo "Searching all JARs recursively..." for eachjar in `find . -iname "*.jar"` do #echo "Searching in $eachjar ..." jar tvf $eachjar | grep $CLASSNAMETOFIND > /dev/null if [ $? == 0 ] then echo "******* Located "$CLASSNAMETOFIND" in $eachjar *******" fi done [/bash]