According to the Java Info.plist Key Reference for Mac, you’re supposed to be able to use the $APP_PACKAGE variable to be able to access the root directory of a Mac Application bundle. So I figure that I can store a file in the Contents/Resources/ folder and access it by calling
new File("$APP_PACKAGE/Contents/Resources/MyFile.txt")
However, this doesn’t seem to work and I simply get a file not found error. Moreover, I’ve tried the following to see if I could narrow down the problem:
new File("$APP_PACKAGE/Contents").exists() //Returns false
System.out.printline(new File("$APP_PACKAGE").getParent()) //Returns an empty string
I did generate the Mac OS X bundle using Eclipse’s Export to Mac OS X application bundle, if that matters. Any help (or a suitable workaround) would be greatly appreciated!
I figured it out! Even though the app had a hard time telling me what the working directory is, I managed to figure out that it is the folder that the application is in. Then I was able to solve it by referring to the app as a directory:
I’d also like to add that I found the suggestion on this blog post to add the following to my info.plist file:
Unfortunately, this doesn’t seem to work on Mac OS 10.7.5 and the working directory just gets reset to the folder that the application is in.