4

I'm wanting to recursively search my maven repository (an n folder deep heirachy of jars) for a specific class inside an unknown jar.

jar -tvf myJar.jar | grep ClassIWant.class works great for a known jar but I'm having problems piping/chaining bash commands to achieve a recursive search.

Any hints much appreciated.

Related: BASH :: find file in archive from command line

Community
  • 1
  • 1
markdsievers
  • 7,151
  • 11
  • 51
  • 83
  • Sorry, forgot to mention, I could probably get something going as a script, but was ideally hoping for a one liner. – markdsievers Oct 15 '10 at 02:52
  • Found the same question answered here http://stackoverflow.com/questions/1500141/find-a-jar-file-given-the-class-name – markdsievers Oct 15 '10 at 03:08

3 Answers3

9
find -name \*.jar | xargs -n1 -iFILE sh -c "jar tvf FILE | sed -e s#^#FILE:#g" | grep classIWant\\.class | cut -f1 -d:
gawi
  • 13,940
  • 7
  • 42
  • 78
3

Bash 4+

shopt -s globstar
for file in **/*.jar
do
  jar -tvf "$file" | grep ....
done

<4++

find /path -type f -name "*.jar" | while read -r FILE
do
     jar -tvf "$FILE" | grep ....
done
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
3

Post already exists. Solved here Find a jar file given the class name? Thanks for the alternatives.

Community
  • 1
  • 1
markdsievers
  • 7,151
  • 11
  • 51
  • 83