Hi everyone !
I'm facing a problem since I'm migrating my app from Java6 to Java8 for MacOS (and other OS but with windows/linux there is NO problem !).
When I was using Java6 I used MacOS APP "App Bundler" to do the package.
This tools reference to a plist file that contains all package information and provide the ability to add an option "WorkingDirectory" and a variable $APP_PACKAGE to set the working directory of the package inside the package like that:
<key>WorkingDirectory</key>
<string>$$APP_PACKAGE/Contents/Resources/Java</string>
Unfortunately, this option "WorkingDirectory" does not exist with the bundler appbundler that provides support for Java 6 superior versions.
So I googled a lot and found this issue; Apple Issue
So I added <option value="-Duser.dir=$APP_ROOT/Contents/Resources"/>
to my plist file via ant task like that:
<key>JVMOptions</key>
<array>
<string>-Xdock:icon=Contents/Resources/${bundle.icon}</string>
<string>-Duser.dir=$APP_ROOT/Contents/Resources</string>
</array>
And I tied also this:
<option value="-Duser.dir=$APP_ROOT/Contents/Java" />
<argument value="-Duser.dir=$APP_ROOT/Contents/Java"/>
Without success :-(
And I added a big "verrue" on early start of my Java application like that (as said here):
String os = System.getProperty("os.name").toLowerCase();
System.out.println("os:" +os);
if (os.indexOf( "mac" ) >= 0){
try {
System.setProperty("user.dir", new File(".").getCanonicalPath());
System.out.println("user dir:" +System.getProperty("user.dir"));
System.out.println(new File(".").toURI());
System.out.println("Working directory: "+(new File(".").getCanonicalPath()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
But nothing works; when I was creating file from the previous Java application they were created into the application working dir like /Applications/MyApp.app/Content/Java
, but know when I create a file/folder it is created under /Users/MyUserName
I also follow this PATCH (I post a question) and compile a new jar but the <string>-Duser.dir=$APP_PATH/Contents/Java</string>
does not do the job, the env variable is not user system created and used!
It's driving me silly... Any idea ? Regards !!
[EDIT1] As a workaround and because it is also simple but too bad I just changed all my relative paths (some at least !) like that:
String path = new File(".").getCanonicalPath();
File myFile = new File(path+File.separator+"MyFile");
It acts similar to set the working directory variable but I have to change a lot of my code rather than use a single option (and on Linux and Windows I do not have this type of problem) :-( Anyway thanks to Trejkaz to have answer on my issue... and sorry for my misspellings and my poor English.
Another time, Regards !!
[EDIT2] So I edited all my relative paths but I had a second problem with the appbundle: Every ProcessBuilder commands fails when launched by the bundle but succeed when clicking on the jar so I used "desktop" intead like this:
DesktopApi desktopApi = new DesktopApi();
desktopApi.open("path-to-my-jar"+File.Separator+"MyJar.jar");
I use the class 'DesktopApi' found here coded by MightyPork (Regards !!) as sometimes desktop command provided by JRE fails...
So I'm done with this fu***** packaging now !!! Regards !!