Find in jar, zip or any archive

in

Finding classes in jar files must be one of the main activities of Java developers.

Here's my version of the "find in jars" utility. Note that the same idea can be used to find files inside zip or any other archive file.


#!/bin/sh
for f in `find -name '*.jar'`; do (unzip -t "$f" | grep $1) && echo "Found in: $f"; done

NOTES:
* I used `unzip` instead of `jar` because the machine I was using at the time did not have the JDK. It's too complicated to explain. To use `jar` just replace

unzip -t "$f"

with

jar tf "$f"

* The script searches in the current folder and subfolders for .jar files only. Change as appropriate.