I have a Java app which I am packaging to a Mac Application Bundle (That folder structure that contains all of the app but looks like a single executable file to the user).
My Problem:
I am reading and writing some config files in the local folder (“.”). However, on Mac this seems to be the folder in which the application bundle is located (so usually the “Applications” folder and I obviously don’t want that.
My question:
How can I store a file inside that bundle? How can I programmatically retrieve the bundle name to compute the fully qualified folder?
I know I could try to go the ClassLoader way, but I’d like to avoid that (for security reasons).
Or is there simply a better way how to store application cache and config data locally?
Ok, the basic answer / solution is: don’t do it.
The reason I originally wanted to do it was to cache larger amounts of data on the local HD. Java preferences are a good choice for config data (i.e. small data amounts) but fail to handle data in the megabyte size range.
My solution:
On MacOSX (
System.getProperty("os.name").contains("Mac OS X")) I simply create a folder in the user’s home folder (System.getProperty("user.home")). I prefix that folder with a.to ensure it is hidden from the user. This also ensures that I have write access to the folder (which could be a problem in the .app folder depending on where the user copies it)On Windows (
System.getProperty("os.name").contains("Windows")) I create that folder in theSystem.getenv("APPDATA")directory (note that this env variable only exists on Windows systems.Now I have full access to the filesystem (even without admin rights) and can store as much data as I like.