I'm trying to find which jar contain a class, I wrote the below, which doesn't seem to work any ideas?
find -type f -name "*.jar" -exec jar -tvf "{}" \| grep MyClass \; -ls
That doesn't work, because find calls exec(3) directly, and as such, does not interpret the command line as a shell does (to set up the pipe).
When I need to do something like this, I generally toss the stuff I want piped into a script, so that I can do -exec script {} \;. Another option is
find . -type f -name "*.jar" -exec sh -c "jar -tvf '{}' | grep MyClass" \; -ls
FWIW, my personal findClassInJar is
for x in `find . -name "*.jar" -o -name "*.zip"` ; do if unzip -l $x | grep -q $1 > /dev/null ; then echo $x ; fi ; done
It won't work with directories with spaces in them, but I just don't do that in a project.
I am not quite sure what you are wanting... Here is a bit of bash that displays the filename of a .jar file containing a .class file.
for f in `find *.jar`; do if jar -tvf $f | grep class &>/dev/null; then echo $f; fi; done
You can remove the echo $f statement and put your own customization there, as well as customizing the grep command in it.
Hope it helps.