Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading resources from a jar file

 
Lisa Boslett
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
you will have to use
resourceLoader.getResourceStream(resourceName)
instead of resourceLoader.getResource(resourceName)
to load a properties file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic