Searching for a String in (a) JAR file - Java

This is one of the common problems faced by almost every Java developer, when they want to search for a String and they are not sure where it is really coming from.

While looking at all the possible solutions, not the cheesy ones with so many libraries to use, I found out that Linux wins the race again with just 1 line of command.

find . -iname '*.jar' -printf "unzip -c %p | grep -q '' && echo %p\n" | sh
You can make it more useful by echoing, aliasing, and converting it to a script instead so that you don't have to type this command all the time. 

printf "Searching for string in JARs '${1}'...\n"
find . -iname '*.jar' -printf "unzip -c %p | grep -q '${1}' && echo %p\n" | sh

 here, ${1} will be string you want to search. 

Comments