I ran this
find . -name '*.jar' | xargs jar tf
hoping it would, find all the .jar files and execute jar tf on them (to view the content).
But it didn't seem to work!!!
I ran this
find . -name '*.jar' | xargs jar tf
hoping it would, find all the .jar files and execute jar tf on them (to view the content).
But it didn't seem to work!!!
You're using xargs and jar tf the wrong way.
The original purpose of xargs is to pass as many files as it can at once – so you end up with a few jar tf file1 file2 file3 file4 ... file200 ... invocations.
But jar t, much like tar t, only accepts one .jar file at once. All remaining arguments act as filters for what to list/extract. For example, jar tf thing.jar org/example would only list files from the "org/example" subdirectory.
So if you run jar tf file1.jar file2.jar file3.jar, it only reads file1.jar, and expects the rest to match files within the archive.
So instead you need to tell xargs to run the command once per file:
find ... | xargs -d '\n' -n 1 jar tf
(The -d '\n' option has nothing to do with your problem, but it is a good idea nevertheless – just in case you happen to find some files with spaces in their names.)
A more direct way of doing the same is:
find ... -exec jar tf {} \;