Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8306974

[macos] Current working directory wrong when running jpackage app

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      macos version 12.2; OpenJDK version 20.0.1 or version 19.0.2

      A DESCRIPTION OF THE PROBLEM :
      When running an application created by jpackage, searching for the current working directory returns "/".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Generate the installation of an application (with jpackage) which searches for its execution directory.
      2) Install the app.
      3) Launch the app to check what it found.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The absolute path to the application's runtime directory.

      ---------- BEGIN SOURCE ----------
      public class Test {
          public static void main (String[] args) {
           String oneWay;
      String oneOtherWay;
      String resultFilePath;
      try {
      oneWay = new java.io.File( "." ).getCanonicalPath();
      oneOtherWay = System.getProperty("user.dir");

      //As the console is not supported under macos with jpackage applications the result is saved in the file /Users/.../tmp/resultFile.txt
      resultFilePath = System.getProperty("user.home") + "/tmp/resultFile.txt";
      BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath));
      writer.write(" oneWay : \"" + oneWay + "\"\n oneOtherWay : \"" + oneOtherWay + "\"\n");

      writer.close();
      } catch (Exception e) {
      e.printStackTrace();
      }
          }
      }
      ---------- END SOURCE ----------

            almatvee Alexander Matveev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: