File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JNLP and Web Start and the fly likes accessing resource files that are jarred in javawebstart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "accessing resource files that are jarred in javawebstart" Watch "accessing resource files that are jarred in javawebstart" New topic
Author

accessing resource files that are jarred in javawebstart

Lemig Gimeno
Greenhorn

Joined: Apr 11, 2006
Posts: 4
Hi, what is the best way to access a jar file ( eg., a resource file) using Java Webstart.
I put in my code and resource files into two jars:
myCode.jar
myResource.jar

But I found that I have to rewrite a bunch of my program files in myCode.jar to access the music and images that I have in myResource.jar since for example

String test = "images/pic.png"
Image some = new ImageIcon(test).getImage();

will need to be change into something like

ClassLoader classload = getClassLoader().getResource("images/pic.png);
URL url = classload.something.something();
String test = url.toString();
Image some = new ImageIcon(test).getImage();

This has led to some frustration since ( right now ) my program is messed up and it not working hehe. I'm thinking of making a GetResourceFromJar.java that would assume that the resource files are already in some jar. Does anybody has a better solution?
James Ridley
Greenhorn

Joined: Apr 21, 2006
Posts: 15
As long as both of your jar files are listed as resource, you should be able to use code like the following to access images:



I believe this would be the preferred method for loading properties files, images, etc that are bundled within jar files as you can use either ClassLoader.getResource(String) or ClassLoader.getResourceAsStream(String) to find them.
Lemig Gimeno
Greenhorn

Joined: Apr 11, 2006
Posts: 4
Hi, thanks for the help. I tried it for my image files and it worked but there seemed to be some problems for the text files and sound files.
 
wood burning stoves
 
subject: accessing resource files that are jarred in javawebstart