Java – How to search for a string in JAR files


My application is built on Java EE.

I have approximately 50 jars in this application.

Is it possible to search for a particular keyword (actually I want to search for a keyword BEGIN REQUEST)?

Best Solution

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:

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" {}'