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

[macos] the working directory is unexpectedly set to the system root folder

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      os_x

      Description

      ADDITIONAL SYSTEM INFORMATION :
      macOS Mojave 10.14.6, Compiling and jlinking with OpenJDK/OpenJFX 13.0.2. Packaging with the latest OpenJDK 14 EA.

      A DESCRIPTION OF THE PROBLEM :
      I tried to package a JavaFX application with the latest jpackage available on Java 14 EA. This generates a macOS application as expected but the working folder is set by default to "/" when I launch the application by double-clicking on the application root folder.
      When I go inside the application folder and double-click on <app root>/Contents/MacOS/<app exec>, the working folder becomes "~/".

      I would expect the application to be something like <app root>/Contents/app.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a OpenJDK 13 / Maven project with Netbeans 11.2 using the source code provided.
      2. Compile this Maven project in order to get a dmg file.
      3. Double-click on this dmg file and install the application in the Application folder.
      4. Double-click on the installed application to launch it

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Launching the application should pop up a JavaFX window giving the current working folder.
      The current working folder should be "/Application/<application name>/Contents/app"
      ACTUAL -
      The current working folder is "/"

      ---------- BEGIN SOURCE ----------
      // App.java
      package com.mycompany.mavenproject1;

      import java.nio.file.Path;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      /**
       * JavaFX App
       */
      public class App extends Application {

          @Override
          public void start(Stage stage) {
              var path = Path.of(".").toAbsolutePath();
              var label = new Label("Hello, JavaFX.\nWorking folder: " + path.toString());
              var scene = new Scene(new StackPane(label), 640, 480);
              stage.setScene(scene);
              stage.show();
          }

          public static void main(String[] args) {
              launch();
          }

      }

      // pom.xml
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.mycompany</groupId>
          <artifactId>mavenproject1</artifactId>
          <version>1.0-SNAPSHOT</version>
          <properties>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
              <maven.compiler.source>11</maven.compiler.source>
              <maven.compiler.target>11</maven.compiler.target>
              <jpackage.home>${java.home}/../../../jdk-14.jdk/Contents/Home</jpackage.home>
          </properties>
          <dependencies>
              <dependency>
                  <groupId>org.openjfx</groupId>
                  <artifactId>javafx-controls</artifactId>
                  <version>13</version>
              </dependency>
          </dependencies>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>3.8.0</version>
                      <configuration>
                          <release>11</release>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-dependency-plugin</artifactId>
                      <version>3.1.1</version>
                      <executions>
                          <execution>
                              <id>copy-libs</id>
                              <phase>prepare-package</phase>
                              <goals>
                                  <goal>copy-dependencies</goal>
                              </goals>
                              <configuration>
                                  <outputDirectory>${project.build.directory}/modules</outputDirectory>
                                  <includeScope>runtime</includeScope>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <groupId>com.coderplus.maven.plugins</groupId>
                      <artifactId>copy-rename-maven-plugin</artifactId>
                      <version>1.0.1</version>
                      <executions>
                          <execution>
                              <id>copy-target</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>copy</goal>
                              </goals>
                              <configuration>
                                  <sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
                                  <destinationFile>${project.build.directory}/modules/${project.build.finalName}.jar</destinationFile>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <groupId>org.moditect</groupId>
                      <artifactId>moditect-maven-plugin</artifactId>
                      <version>1.0.0.Beta2</version>
                      <executions>
                          <execution>
                              <id>create-runtime-image</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>create-runtime-image</goal>
                              </goals>
                              <configuration>
                                  <modulePath>
                                      <path>${project.build.directory}/modules</path>
                                  </modulePath>
                                  <modules>
                                      <module>com.mycompany.mavenproject1</module>
                                  </modules>
                                  <stripDebug>true</stripDebug>
                                  <compression>2</compression>
                                  <no-header-files>true</no-header-files>
                                  <no-man-pages>true</no-man-pages>
                                  <ignoreSigningInformation>true</ignoreSigningInformation>
                                  <jdepsExtraArgs>
                                      <args>-strip-native-commands</args>
                                      <arg>-multi-release</arg>
                                      <arg>9</arg>
                                  </jdepsExtraArgs>
                                  <outputDirectory>${project.build.directory}/jlink</outputDirectory>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>exec-maven-plugin</artifactId>
                      <version>1.6.0</version>
                      <executions>
                          <execution>
                              <goals>
                                  <goal>exec</goal>
                              </goals>
                              <configuration>
                                  <executable>${java.home}/bin/java</executable>
                                  <arguments>
                                      <argument>--module-path</argument>
                                      <argument>${project.build.directory}/modules</argument>
                                      <argument>--module</argument>
                                      <argument>com.mycompany.mavenproject1/com.mycompany.mavenproject1.App</argument>
                                  </arguments>
                              </configuration>
                          </execution>
                          <execution>
                              <id>create-package</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>exec</goal>
                              </goals>
                              <configuration>
                                  <!-- compiling with OpenJDK 13 GA but packaging with OpenJDK 14 EA as 14 GA isn't available yet and 13 GA doesn't have javapackager.exe nor jpackage.exe -->
                                  <!-- GA (General Availability) = final version, EA (Early Access) = beta version -->
                                  <executable>${jpackage.home}/bin/jpackage</executable>
                                  <workingDirectory>${project.build.directory}</workingDirectory>
                                  <longModulepath>false</longModulepath>
                                  <environmentVariables>
                                      <JAVA_HOME>${jpackage.home}</JAVA_HOME>
                                  </environmentVariables>
                                  <arguments>
                                      <argument>--app-version</argument>
                                      <argument>${project.version}</argument>
                                      <argument>--name</argument>
                                      <argument>${project.name}</argument>
                                      
                                      <argument>--runtime-image</argument>
                                      <argument>${project.build.directory}/jlink</argument>
                                      
                                      <argument>--module</argument>
                                      <argument>com.mycompany.mavenproject1/com.mycompany.mavenproject1.App</argument>
                                  </arguments>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
      </project>
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

        1. App.java
          0.7 kB
        2. pom.xml
          8 kB
        3. SwingApp.java
          1 kB

          Issue Links

            Activity

              People

              Assignee:
              herrick Andy Herrick (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: