View Single Post
  #1 (permalink)  
Old 01-27-2008, 07:14 PM
jimm1 jimm1 is offline
Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 18
jimm1 has a little shameless behaviour in the past
Problem loading resources.
This is a problem that has been bothering me for over a month, and I still can't find a fix, yet this problem is really simple!

I have a program (In JAR format) that loads resources from a folder (Which is in the same directory as the JAR file).

I'm using Linux. If I run the program from the shell (java -jar organiser.jar) it runs fine. But now I want to make my program more professional and user friendly, so of course I will assume normal people will double click on the JAR icon. (Normal people DO NOT USE COMMAND LINE). However unfortunately, if I try making a shortcut to the JAR, or run it from the Nautilus browser on Linux, it assumes the working directory is in my home directory, and hence looks for the resources in the wrong place! If I use getClass.getResource() that works fine, however I dont only want to read resources, I also need to write resources, and if I use relative filenames it writes/reads them from the wrong place. I do NOT want to use full pathnames, that will mean I have to have 2 versions for Linux and Windows. Is there some way of bypassing this?
Reply With Quote
Sponsored Links