Rahel Lüthy
Rahel Lüthy

Reputation: 7007

How to programmatically search text in jar file?

I want to search my sources.jar for the occurrence of a certain search token.

In Bash, this will extract the jar to a stream and grep for the string:

unzip -p sources.jar | grep $SEARCH_TOKEN

In Java, reading all entries via JarInputStream looks rather tedious. Is there a better/simpler way (for both, the looping and the grepping)?

Upvotes: 0

Views: 577

Answers (1)

Stephen C
Stephen C

Reputation: 718886

Is there a better/simpler way (for both, the looping and the grepping)?

In short, No (probably).

(I guess you might get lucky, and find an existing Java utility command someone has already written. I don't rate your chances though.)


UPDATE

It is your lucky day!

http://metastatic.org/source/Jargrep.java

Note that the code is GPL 2. Respect the license!

Upvotes: 1

Related Questions