List contents of multiple jar files
You need to pass -n 1
to xargs
to force it to run a separate jar
command for each filename that it gets from find
:
find -name "*.jar" | xargs -n 1 jar tf
Otherwise xargs
's command line looks like jar tf file1.jar file2.jar...
, which has a different meaning to what is intended.
A useful debugging technique is to stick echo
before the command to be run by xargs
:
find -name "*.jar" | xargs echo jar tf
This would print out the full jar
command instead of executing it, so that you can see what's wrong with it.
I faced a similar situation where I need to search for a class in a list of jar files present in a directory. Also I wanted to know from which jar file the class belongs to. I used this below code snippet(shell script) and found out to be helpful. Below script will list down the jar files that contains the class to be searched.
#!/bin/shLOOK_FOR="codehaus/xfire/spring"for i in `find . -name "*jar"`do echo "Looking in $i ..." jar tvf $i | grep $LOOK_FOR > /dev/null if [ $? == 0 ] then echo "==> Found \"$LOOK_FOR\" in $i" fidone
Shell script taken from : http://alvinalexander.com/blog/post/java/shell-script-search-search-multiple-jar-files-class-pattern