I'm trying to compile a Java application into a Mac OS X app bundle. I add the following setting to set the current working directory:
<bundleapp...>
...
<option value="-Duser.dir=$APP_ROOT/Contents/Resources"/>
</bundleapp>
In Contents/Resources/ there is a config directory.
When executing it, I get this strange behaviour :
new File("config/").exists()
returns false
new File("config/").getAbsolutePath()
returns /path/to/bundled/app/MyApp.app/Contents/Resources/config
new File("config/").getAbsoluteFile().exists()
returns true
I don't know why this happens and I would like to prevent adding getAbsoluteFile() everywhere in my code.
Any thoughts on this?
(Note: I'm using Oracle JDK 8)
getAbsolutePath
resolves relative paths against current user.dir
property. From javadocs:
On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory.
Although javadocs states that
By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
this bug report states that "simpler" getters (not "absolute") for relative paths will resolve against the path the virtual machine was invoked.