This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List resources in a jar

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18366
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic