• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

List resources in a jar

 
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.
 
Saloon Keeper
Posts: 22482
151
Android Eclipse IDE Tomcat Server Redhat Java 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.
 
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
...
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic