wood burning stoves 2.0*
The moose likes JNLP and Web Start and the fly likes Reading resources from a jar file 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 "Reading resources from a jar file" Watch "Reading resources from a jar file" New topic
Author

Reading resources from a jar file

Lisa Boslett
Greenhorn

Joined: Apr 23, 2002
Posts: 1
I am new to Java Web Start. I need to be able to read a file from the jar. My application has many configuration files along with some input files, and I need to be able to access them. I have tried every way that you suggest, but I keep getting a null. It cannot find the resource. I am at my wits end. I tried both the Rachel suggestions and also the Resource Loading Tutorial and I keep getting a null when I get the resource. All the examples that I see are for icons and properties.
I made sure that the file exists in the jar. I made sure that the file path was correct. I made sure I was getting the correct classloader. Any suggestions?
My signed jar file is nxm.jar and when I look inside I can see the file is:
nxm\sys\cfg\commands.cnf
The code that I am using (at this point I went back to the classloader)
...
String resourceName;
ClassLoader resourceLoader = ResourceAnchor.class.getClassLoader();
URL resourcePath = new URL( resourceLoader.getResource(resourceName) );
...
Note:
-When I printout the "resourceName" it is nxm\sys\cfg\commands.cnf
-I am on a Windows NT platform
What am I doing wrong?
Thanks in Advance,
Lisa Boslett
M.K.A. Monster
Ranch Hand

Joined: May 02, 2002
Posts: 130
Hava you tested the Jar-file without the JNLP file? for example:
java -jar Program.jar
Make sure you have added a Manifest file to the Jar-file.
If this works, and the JNLP doesn't work, I think you've made a mistake while building up the JNLP file.
gowrish bhaskar
Greenhorn

Joined: Oct 03, 2001
Posts: 9
Hi,
you will have to use
resourceLoader.getResourceStream(resourceName)
instead of resourceLoader.getResource(resourceName)
to load a properties file


Regards,<br />Gowrish.B<br />gowrishb@hotmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading resources from a jar file