How to search for a string in JAR files

后端 未结 10 1099
小蘑菇
小蘑菇 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:36

    The below command shows the results with the file name and jar file name.

    1. To find the string in the list of jar file.

      find <%PATH of the Folder where you need to search%> -name "*.jar" -print -exec zipgrep "jar$|<%STRING THAT YOU NEED TO FIND>" '{}' \;
      
    2. To find the class name in the list of jar file.

      find . -name "*.jar" -print -exec jar tvf {} \; |grep -E "jar$|<%CLASS NAME THAT YOU NEED TO FIND>\.class"
      
    0 讨论(0)
  • 2020-12-12 15:37

    in android i had to search both jar and aar files for a certain string i was looking for here is my implementation on mac:

    find . -name "*.jar" -o -name "*.aar" | xargs -I{} zipgrep "AssestManager" {}
    

    essentially finds all jars and aar files in current direclty (and find command is recursive by default) pipes the results to zipgrep and applies each file name as a parameter via xargs. the brackets at the end tell xargs where to put the file name you got from the find command. if you want to search the entire home directory just change the find . to find ~

    0 讨论(0)
  • 2020-12-12 15:40

    Searching inside a jar or finding the class name which contains a particular text is very easy with WinRar search. Its efficient and always worked for me atleast.

    just open any jar in WinRar, click on ".." until you reach the top folder from where you want to start the search(including subfolders).

    Make sure to check the below options:

    1.) Provide '*' in fields 'file names to find', 'Archive types'

    2.) select check boxes 'find in subfolders', 'find in files', 'find in archives'.

    0 讨论(0)
  • 2020-12-12 15:45

    Caution: This is not an accurate answer, it's only a quick heuristic approach. If you need to find something like the name of a class (e.g., which jar has class Foo?) or maybe a method name, then this may work.

    grep --text 'your string' your.jar
    

    This will search the jar file as if it were text. This is quicker because it doesn't expand the archive, but that is also why it is less accurate. If you need to be exhaustive then this is not the approach you should use, but if you want to try something a little quicker before pulling out zipgrep this is a good approach.


    From man grep,

      -a, --text
              Process  a binary file as if it were text; this is equivalent
              to the --binary-files=text option.
    
    0 讨论(0)
提交回复
热议问题