How to search for a string in JAR files

后端 未结 10 1124
小蘑菇
小蘑菇 2020-12-12 14:57

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 s

10条回答
  •  粉色の甜心
    2020-12-12 15:19

    One-liner solution that prints file names for which the search string is found, it doesn't jam your console with unnecessary "searching in" logs::

    find libdir -wholename "*.jar" | xargs --replace={} bash -c 'zipgrep "BEGIN REQUEST" {} &>/dev/null; [ $? -eq 0 ] && echo "{}";'
    

    Edit:: Removing unnecessary if statement, and using -name instead of -wholename (actually, I used wholename, but it depends on your scenario and preferences)::

    find libdir -name "*.jar" | xargs --replace={} bash -c 'zipgrep "BEGIN REQUEST" {} &>/dev/null && echo "{}";'
    

    You can also use sh instead of bash. One last thing, --replace={} is just equivalent to -I{} (I usually use long option formats, to avoid having to go into the manual again later).

提交回复
热议问题