This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "List resources in a jar" Watch "List resources in a jar" New topic
Author

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?
Thanks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Hi.
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?
Regards.
Hakan Erdogan
Greenhorn

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) {
   e.printStackTrace();
}



META-INF/MANIFEST.MF 631 Bytes
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: List resources in a jar
 
Similar Threads
where do I put the resources?
JNLP Jar Href and Ant
preparation ressources
opinion poll: readability
What's the right way to pass javac parameters to java:compile in Maven?