This is a follow-up question to this one (just as a brief description: I have been able to run a Java program by double-clicking on the .jar
file on OS X and Windows, but not on Linux, as with the latter I get a file path problem).
Through trying out a few things using NetBeans under Ubuntu (12.04) I found that the problem seems to be located in what the program considers to be its working directory (which I concluded from the output of File.getAbsolutePath()
). If I start my application in NetBeans, everything works (even under Ubuntu), and
System.out.println(new File(".").getAbsolutePath());
gives me /home/my_home/projects/VocabTrainer/.
, which is my project folder and thus correct. However, if I double-click on the .jar
file, located in /home/my_home/projects/VocabTrainer/dist
, the output I get under Ubuntu suddenly is merely /home/my_home/.
This is problematic as I want to access a data file which is located in a sub-directory of my dist
dir.
Does anyone know the cause of this behaviour, and how I can solve the problem?
PS: I don't know if this is required, but here's the output of java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)