wood burning stoves 2.0*
The moose likes Applets and the fly likes listing contents of jar file once its loaded into the local system Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "listing contents of jar file once its loaded into the local system" Watch "listing contents of jar file once its loaded into the local system" New topic
Author

listing contents of jar file once its loaded into the local system

anirudh takkallapally
Greenhorn

Joined: Sep 04, 2003
Posts: 14
Hi,
I have a Config.jar file on the server, which contains xml files inside some subdirectories. When my applet gets loaded the config.jar file loads into my local machine and I can access the files from it using ClassName.class.getResourceAsStream(config\filename.xml);

Now the problem I have to list the entire contents of the config.jar file once I get it onto the local system. I tried something very lame like ClassName.class.getResourceAsStream(config), where config is the name of the directory, so that I could get the directory and once I have that, I could just list the contents of the directory, it didn�t work.

Is there a way of listing the contents once the jar file is loaded into JVM?

Thank you,
anirudh
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Yes.
Look at the ZipFile class.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
That depends what "loaded on the local system" means and what permissions the applet has.
If the jar is being controlled by the plugin, it's not really available outside of the JVM. I don't think there are any API that would be able to look at it. It doesn't really exist as a file for the running program. Its used by the JVM to locate resources such as classes.
If the jar file is on a local drive as a file, then ZipFile (with permission) can see it.
anirudh takkallapally
Greenhorn

Joined: Sep 04, 2003
Posts: 14
Thanks for the reply Norm, i am using URLClassLoader to load the config.jar file into JVM, dont have the jar file on the local file system. The only solution i could come up with is to have a file called directorylisting.xml in the jar file, this directorylisting.xml would contain the list of files and the directory structure inside the jar file and when i need to know the list of files i would just access the directorylisting.xml inside the jar file.

Please do let me know if you have an alternate solution.

thank you,
anirudh
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
That sounds like a good solution.
 
Don't get me started about those stupid light bulbs.
 
subject: listing contents of jar file once its loaded into the local system
 
Similar Threads
Permissions/Jars and Deployment Issues
Issues with Jar Files and loading images
accessing config.jar on a local system from an applet
README.txt
Hibernate 3.3.1 setup help!