How to search for a string in JAR files

You can use zipgrep on Linux or OSX:

zipgrep "BEGIN REQUEST" file.jar

If you wish to search a number of jars, do

find libdir -name "*.jar" -exec zipgrep "BEGIN REQUEST" '{}' \;

where libdir is a directory containing all jars. The command will recursively search subdirectories too.

For windows, you can download cygwin and install zipgrep under it: http://www.cygwin.com/

Edit 1

To view the name of the file that the expression was found you could do,

find libdir -name "*.jar" | xargs -I{} sh -c 'echo searching in "{}"; zipgrep "BEGIN REQUEST" {}'

Edit 2

Simpler version of Edit 1

find libdir -name "*.jar" -print -exec zipgrep "BEGIN REQUEST" '{}' \;

Leave a Comment