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

An app packaged using jpackage cannot launch another app packaged with jpackage

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 17, 25
    • tools
    • x86_64
    • linux

      A DESCRIPTION OF THE PROBLEM :
      An app can naturally launch other commands using mechanisms like ProcessBuilder. It is of course no problem if a compiled java app tries to launch another java app or itself in recursion. However, it seems that an app packaged using jpackage cannot run another app packaged using jpackage or itself recursively.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the attached test case code and package it using jpackage.

      mkdir -p out
      javac -d out App.java

      mkdir -p dist
      jar --create --file=dist/App.jar --main-class=App -C out .

      jpackage \
      --input dist \
      --name App \
      --main-jar App.jar \
      --main-class App \
      --add-modules java.base \
      --type app-image

      The main class accepts an arbitrary number of arguments and launches a new process from the arguments specified. For example:

      ./App/bin/App [command] <[args...]>

      It works to run ordinary programs like the following:

      ./App/bin/App ls -og

      But when trying to launch another app packaged using jpackage or, for the sake of testing things, the same app in recursion, it fails.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The app can launch a process that starts another app packaged using jpackage or itself. Examples:

      Command 1: ./App/bin/App ./App/bin/App
      Output: [stdout] Please specify a command to run and optional arguments

      Command 2: ./App/bin/App ./App/bin/App ls
      Output:
      [stdout] [stdout] App
      [stdout] [stdout] App.java
      [stdout] [stdout] dist
      ... (and the rest of the files from ls command output)

      ACTUAL -
      Command 1: Displays the output of "java -help" command
      Command 2: [stdout] Error: Could not find or load main class ls
      [stdout] Caused by: java.lang.ClassNotFoundException: ls

      ---------- BEGIN SOURCE ----------
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStreamReader;

      class App {

          public static void main(String[] args) throws IOException {
              if (args.length < 1) {
                  System.out.println("Please specify a command to run and optional arguments");
                  System.exit(1);
              }

              // Forward all arguments to the process builder
              Process process = new ProcessBuilder(args).redirectErrorStream(true).start();

              // Start a new thread to forward the launched thread's output to our own stdout
              Thread gobbler = new Thread(() -> {
                  try (BufferedReader reader = new BufferedReader(
                          new InputStreamReader(process.getInputStream()))) {
                      String line;
                      while ((line = reader.readLine()) != null) {
                          System.out.println("[stdout] " + line);
                      }
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              });

              gobbler.start();
          }

      }
      ---------- END SOURCE ----------

            pmtavare Patricia Tavares
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: