File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java Micro Edition and the fly likes List resources in a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "List resources in a jar" Watch "List resources in a jar" New topic

List resources in a jar

Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Hi. Is there a way to list all resources in a jar file? Judging by what I found, the answer is no (I haven't found anything ;d), but who knows?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

A JAR file is just an ordinary ZIP file that includes a META-INF/MANIFEST.MF file in it. So you can list what's in a JAR using any ZIP utility. Or use the "tv" option on the "jar" utility that comes with the JDK.

An IDE is no substitute for an Intelligent Developer.
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
I wasn't specific enough, sorry for that.
I meant I want to list resources at runtime, on a mobile phone. As far as I can see MIDP doesn't support any Zip/JarInputStream. With the Java classloaders, you know that a Class belongs to a package after you load it, which makes it impossible to list all classes in a package. As resource loading use classloaders, I guess there is the same issue, but maybe there exists some way to do that?
Hakan Erdogan

Joined: Jun 30, 2006
Posts: 10
try {
   JarFile jarFile = new JarFile("C:\\log4j.jar");
   Enumeration<JarEntry> enumeration = jarFile.entries();
   while (enumeration.hasMoreElements()) {
      JarEntry jarEntry = (JarEntry) enumeration.nextElement();
      System.out.println(jarEntry.getName()+" "+jarEntry.getSize()+" Bytes");
} catch (IOException e) {

META-INF/ 0 Bytes
org/ 0 Bytes
org/apache/ 0 Bytes
org/apache/log4j/ 0 Bytes
org/apache/log4j/Appender.class 676 Bytes
org/apache/log4j/AppenderSkeleton.class 3619 Bytes
org/apache/log4j/AsyncAppender$DiscardSummary.class 1604 Bytes
org/apache/log4j/AsyncAppender$Dispatcher.class 2487 Bytes

SCJP 1.4
I agree. Here's the link:
subject: List resources in a jar
It's not a secret anymore!