3

Maybe I'm just having a brain dead day but, what is the easiest/best way to get the contents of all jars in a given directory?

I'm running into a classpath/loader conflict so I want a way to get a list of the entire contents of all the jars to find my problem. I know that there are some tools that will help with this but, for the life of me, I can't think of any of them.

Any thoughts?

EDIT:
For reference, here's what I've been doing (this is broken up for readability but I just do it all on one line as a shell script):

OUTFILE=/tmp/allClasses.txt ; 
touch $OUTFILE; 
for file in *.jar; 
do echo " === $file " >> $OUTFILE; 
jar -tf $file >> $OUTFILE; 
done;

This seems to work pretty well but it just feels clunky.


For reference, here's what I've been doing: touch /tmp/allClasses.txt ; for file in *.jar ; do echo " === $file " >> /tmp/allClasses.txt ; jar -tf $file >> /tmp/allClasses.txt ; done;

This seems to work pretty well but it just feels clunky.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
grauwulf
  • 376
  • 2
  • 13
  • 1
    Take a look at [`ZipInputStream#getNextEntry()`](http://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipInputStream.html#getNextEntry()). – Eng.Fouad Jul 31 '13 at 16:03
  • 1
    [Here is an example](http://stackoverflow.com/a/15720973/597657). – Eng.Fouad Jul 31 '13 at 16:03
  • Thanks for moving that up Steve. Editing to improve the script in case anyone else want's to use it. – grauwulf Jul 31 '13 at 16:10

4 Answers4

2

open the jar-file as an archive with Winrar or 7zip

Joris W
  • 517
  • 3
  • 16
  • I'm aware that you can open a jar with zip tools but I'm not aware of one that allows you to easily extract information about the contents of a large number of files at once. – grauwulf Jul 31 '13 at 17:06
1

jar xf jar-file extracts the contents of a JAR file.

  • It does, yes. The OP has been edited to show what I'm doing now (using something similar to this) but I'm looking for a more efficient way to do it on a large number of files. – grauwulf Jul 31 '13 at 17:07
0

A jar file is just a zip file (compressed or not), you can even change its extension from jar to zip and unzip it

Pablo Lozano
  • 10,122
  • 2
  • 38
  • 59
0

zipinfo can list the contents of several zip (or JAR) files at once:

zipinfo \*.jar

the trick is to escape the * so zipinfo itself expands the wildcard rather than the shell expanding it and then passing the expanded list to zipinfo (which doesn't work as zipinfo expects the first argument to be the archive to look in and the subsequent arguments to be entry paths within that archive).

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183