2

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 !!

Community
  • 1
  • 1
neuronsoverflow
  • 133
  • 4
  • 14
  • I would question setting the user's working directory to inside your bundle. But anyway, the most likely reason that this doesn't work is that appbundler explicitly sets the user directory to the user's home directory on startup. That was one of the things which ultimately prevented us using it for command-line tools and forcing us to write our own launcher from scratch. – Hakanai Jul 30 '14 at 00:17
  • Thank you for your comment. I understand better why it is like that. And what about $APP_ROOT that is provide by appbundler ? Can I use it on my package ? And I also tried the 30-PATCH which seems to set an environmennt variable $APP_PATH but I didn't make it working, echo $APP_PATH is blank and folder/files are created under /Users/myUsername, any idea on why it is not set ? Regards !! – neuronsoverflow Jul 30 '14 at 22:05
  • Not sure. $APP_PATH was something appbundler already had before I started messing with it and one trick I used was to set its value into a system property so that I could get at it from the Java side. – Hakanai Jul 31 '14 at 11:48
  • Thank you for this information. Do you know if this command (ProcessBuilder) : command: [/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java, -jar, /Applications/MyApp.app/Contents/Java/MyApp.jar] fails when launched trought the execution of bundle app but succeed when I just click on the jar ? My question; is there a correlation between the app bundler and this failing command ? – neuronsoverflow Jul 31 '14 at 13:42

0 Answers0