Note that I am talking about Java 7, since the info.plist specification for a Java .app bundle seems to have changed a bit since Java 6.
Currently my code looks like this:
File file = new File( "documentation/index.html" );
if (file.exists()) {
// opens the URI in the browser
GUIUtils.openURI( file.toURI() );
} else {
// opens the URI in the browser
GUIUtils.openURI( getClass().getResource( "/documentation/index.html" ).toURI() );
}
In the Java subfolder in the app bundle, I have a “documentation” subfolder. I have tried multiple things, to no avail:
- In the info.plist, setting the working directory to the Java folder (with a
-Duser.dirJVMArgument property) – the file seemingly has the right path, butfile.exists()returns false. - Trying to set the ClassPath to the Java folder. (
getClass().getResource()still returns null)
If you’re prepared to use the
com.appleextensions,com.apple.eio.FileManager.getPathToApplicationBundle()will give you the base path to your bundle, and you can then create aFilerelative to that.