-1

I am trying to search a specific string in Java code base. I can use simple grep to scan through whole directory structure and it works for string in text based code.

How can I search a string which might be there in .jar file used by some file in Java.

Is there a way to search for a specific string I can search through code as well as in dependent libs.

I am using any IDE. I want to write a script that can search through code.

Gaurav
  • 788
  • 2
  • 13
  • 27
  • If you are using eclipse, you can with Crtl + Shift + R – mvlaicevich Feb 25 '16 at 19:07
  • What IDE are you using? It would be better to leverage your IDE's searching tools. – zero298 Feb 25 '16 at 19:07
  • You can try [this](http://grepcode.com/) – SomeDude Feb 25 '16 at 19:08
  • I am not using IDE. I want to use command line. I need to write a script which can run through it. – Gaurav Feb 25 '16 at 19:09
  • 5
    You have several choices, including [zipgrep](http://www-it.desy.de/cgi-bin/man-cgi?zipgrep+1), or writing your own Java program using [ZipInputStream](https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipInputStream.html) and [Java regex](https://docs.oracle.com/javase/tutorial/essential/regex/). Look here for more suggestions: [How to search for a Word in jar files](http://stackoverflow.com/questions/10331025/how-to-search-for-a-word-in-jar-files) – paulsm4 Feb 25 '16 at 19:10

2 Answers2

0

You can use zipgrep on linux,

zipgrep "your string" file.jar

If you have to find the same thing in number of jars, do

find libdir -name "*.jar" -exec zipgrep "your string" '{}' \;

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

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

Karuna
  • 719
  • 1
  • 11
  • 22
0

To search for text based code you can use grep. Like this:

grep -r "search_word" .

where -r is for making the search recursive.

To search inside jar files, you can use zipgrep on linux. For example:

zipgrep "search_word" file.jar
Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90