Search code examples
javajardecompiler

How can I extract the strings declared inside the java which went into a jar file


Is there a equivalent to the Unix strings command for jar files?

To give an example, if I have this Java file:

public class Foo {
    String foo = "I\'m so meta even this acronym";
}

compiled and placed in bar.jar

I will, ideally, like to run some command on bar.jar which will send the string "I'm so meta" to standard output so I can grep for it.

The problem I am trying to solve is, I'm getting an error message in my Java program, and I will like to know which jar file its coming from.


Solution

  • This should work for you:
    unzip -p your.jar |strings| grep 'your string'

    To search through multiple JAR files in the directory use:
    unzip -p \*.jar |strings| grep 'your string'