I am searching for a .class file inside a bunch of jars.
jar tf abc.jar
works for one file. I tried
find -name "*.jar" | xargs jar tf
prints nothing. The only solution I can think of, is unzip all, then search. Is there a better way? I'm on LUnix.
Edit: When scanning many jars, it is useful to print the jar file name along with the class. This method works well:
find . | grep jar$ | while read fname; do jar tf $fname | grep SchemaBuilder && echo $fname; done
Sample output produced:
1572 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$1.class
1718 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$2.class
42607 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder.class
./XmlSchema-1.3.2.jar
1572 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$1.class
1718 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder$2.class
42607 Wed Jul 25 10:20:18 EDT 2007 org/apache/ws/commons/schema/SchemaBuilder.class
./XmlSchema.jar
I don't see the necessity for using exec, this worked for me in Cygwin on Windows:
If you are using Eclipse, you can create a project and add all jars. You will then be able to find a class in any of the jars.
Find jar files and get all classes and members saved on a txt.
If you coming to this question and you need to extract all jar files in a windows environment, navigate to the directory where you have saved all the jar files and save a batch file with the following content:
By running the batch file, it will extract each jar file in the directory. The only thing here is that it will extract in the same directory where the jar file is.
Here's what I use in Cygwin. It supports section headers per jar file as requested above.
For *nix, drop the ".exe":
You need to pass
-n 1
toxargs
to force it to run a separatejar
command for each filename that it gets fromfind
:Otherwise
xargs
's command line looks likejar 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 byxargs
:This would print out the full
jar
command instead of executing it, so that you can see what's wrong with it.