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

accessing resource files that are jarred in javawebstart

 
Lemig Gimeno
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic