• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a properties file from within a JAR! (quite urgent)  RSS feed

 
Peter Loew
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please provide me a solution? I'm trying to read in a properties file using the class loader as such:



The problem is that it work when I run it from within JDeveloper, but the application must be packaged up and run from a JAR file. After Ant makes the JAR I keep getting NullPointerExceptions at the props.load(...) line above.

Of course the properties file is in the util/ package/directory.

Can someone please help?

P
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is probably in the path. When you run a program from JDeveloper in the Launch Settings you set the path from wich you want to run your program.

It is probable that you are looking for the resouecess in the path that is not compatible with the path when you run your program from the command-line.

Hence, check the path in the Launch Settings and simply make sure it is the same as the one you use when you run you jar from the command line.

I hope this helps.
 
Peter Loew
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Edwin,

The path settings are all the same and I have defined all the libs etc. in the manifest file in the JAR.

I just done more debugging and it turns out that when it works in JDeveloper, it returns the absolute address to the properties file, i.e. C:\...... this is why it isn't working in the jar, I thought it would return the relative location of the resource instead. This is why it returns null - it's simply a path issue but I don't know how to fix it.

Make sense?
 
Peter Loew
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's OK I solved it.

For some reason or another the file name in the path has to be case sensitive, but this does not seem to bother my IDE (JDeveloper) as it worked through there so I didn't really notice.

Thanks for the help - (Peter wipes sweat from brow!)

P
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!