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

Executable produced using JPackage cannot invoke another executable

    XMLWordPrintable

Details

    • x86_64
    • windows
    • Not verified

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11, OpenJDK 21.0.2, 21.0.3 & 22

      A DESCRIPTION OF THE PROBLEM :
      Since JDK 21.0.2 executables produced using JPackage cannot invoke another executable using the ProcessBuilder start method. Although the method returns a valid Process object, the target executable is not invoked. When JPackage from JDK 21.0.1 or earlier is used to produce an executable, there is no problem, even if the JDK packaged in the application image and the compiled code target later JDK versions such as 21.0.2 or 22.

      REGRESSION : Last worked in version 21

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Maven POMs and main class source have been supplied below in the "Source code for an executable test case" field. These are what I produced to illustrate the problem. I have the complete project structure in a zip file which I can supply if needed.

      Alternatively, you should be able to reproduce the problem by doing the following:

      1. You'll need Apache Maven 3.9.2 or later plus JDK 21.0.2 or later, Wix 3.11 and Microsoft . NET Framework 3.5.1 (Required by WIX) installed.
      2. From a base directory of your choosing (${basedir}), create a folder called RunProc-parent and within that, 2 folders, 1 called RunProc and 1 called RunProc-installer.
      3. In ${basedir}\RunProc-parent, save the source given below for the parent POM to a file called pom.xml.
      4. In ${basedir}\RunProc-parent\RunProc, save the source given below for RunProc POM to a file called pom.xml.
      5. In ${basedir}\RunProc-parent\RunProc create the folder structure src\main\java\com\<USERNAME> and save the source given below for Go.java to a file called Go.java in that location.
      6. In ${basedir}\RunProc-parent\RunProc-installer, save the source given below for Installer POM to a file called pom.xml.
      7. Ensure the JAVA_HOME environment variable is set to the location of JDK 21.0.2 or later
      8. In a command prompt window, navigate to ${basedir}\RunProc-parent, then execute the command mvn clean package -Djava.build.version=21 -Djava.compiler.jdk.location="[full path to jdk location]". Obviously adjust the java.build.version parameter according to the target version for the built code.
      9. Assuming the build completes successfully, JPackage has been configured to produce an application image rather than an installation exe, so we can find the built executable of our test in the configured location for the image. By default you should find RunProc.exe at ${basedir}\RunProc-parent\RunProc-installer\target\deploy\RunProc.
      10. If you execute that program with a single parameter of the name of a .exe to run (including full path if it isn't on the path) you will almost certainly find that the named .exe will not run. The one exception to this rule seems to be notepad.exe.

      Simply changing the JAVA_HOME environment variable to point to a JDK of 21.0.1 or earlier and executing the aforementioned mvn command again, results in a RunProc.exe which can successfully execute any .exe supplied as a parameter when running it. This change allows the maven build to use JPackage from that earlier JDK without changing anything else about the build, indicating that the problem seems to be related to the change from JPackage 21.0.1 or earlier to JPackage 21.0.2 or later

       

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Running the RunProc.exe with a single parameter of the name of a .exe to run (including full path if it isn't on the path), should result in that .exe named as a parameter being run
      ACTUAL -
      When JPackage from JDK 21.0.2 or later is used to build RunProc.exe, the .exe named as the parameter is not executed

      ---------- BEGIN SOURCE ----------
      Parent POM:

      <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.<USERNAME></groupId>
        <artifactId>RunProc-parent</artifactId>
        <version>0.0.1</version>
        <packaging>pom</packaging>
        
        <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <java.build.version>22</java.build.version>
          <java.compiler.jdk.location>${java.home}</java.compiler.jdk.location>
        </properties>

        <modules>
      <module>RunProc</module>
      <module>RunProc-installer</module>
        </modules>
        
        <build>
      <pluginManagement>
      <plugins>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.13.0</version>
      <configuration>
      <source>${java.build.version}</source>
      <target>${java.build.version}</target>
      <release>${java.build.version}</release>
      <fork>true</fork>
      <executable>${java.compiler.jdk.location}/bin/javac</executable>
      </configuration>
      </plugin>

      </plugins>
      </pluginManagement>
        </build>
      </project>

      ======================================================

      RunProc POM:

      <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
          <groupId>com.<USERNAME></groupId>
          <artifactId>RunProc-parent</artifactId>
          <version>0.0.1</version>
        </parent>
        
        <artifactId>RunProc</artifactId>
        <packaging>jar</packaging>

        <build>
      <plugins>

      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.3.0</version>
      <configuration>
      <archive>
      <manifest>
      <mainClass>com.<USERNAME>.Go</mainClass>
      </manifest>
      </archive>
      </configuration>
      </plugin>

      </plugins>
        </build>
      </project>

      ======================================================

      Installer POM:

      <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
          <groupId>com.<USERNAME></groupId>
          <artifactId>RunProc-parent</artifactId>
          <version>0.0.1</version>
        </parent>

        <artifactId>RunProc-installer</artifactId>

        <properties>
          <deployment.location>${project.build.directory}/deploy</deployment.location>
          <assembly.location>${project.build.directory}</assembly.location>
        </properties>

        <build>
      <plugins>

      <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
      <execution>
      <phase>initialize</phase>
      <configuration>
      <target>
      <mkdir dir="${assembly.location}/lib" />
      </target>
      </configuration>
      <goals>
      <goal>run</goal>
      </goals>
      </execution>
      </executions>
      </plugin>

      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>3.6.1</version>
      <executions>
      <execution>
      <id>copy-dependencies</id>
      <phase>package</phase>
      <goals>
      <goal>copy-dependencies</goal>
      </goals>
      <configuration>
      <includeScope>runtime</includeScope>
      <outputDirectory>${assembly.location}/lib</outputDirectory>
      </configuration>
      </execution>
      </executions>
      </plugin>

      <plugin>
      <groupId>org.panteleyev</groupId>
      <artifactId>jpackage-maven-plugin</artifactId>
                  <version>1.6.3</version>
      <executions>
      <execution>
      <phase>package</phase>
      <goals>
      <goal>jpackage</goal>
      </goals>
      </execution>
      </executions>
                  <configuration>
      <!-- <type>MSI</type>-->
                      <name>RunProc</name>
                      <verbose>true</verbose>
               <runtimeImage>${java.compiler.jdk.location}</runtimeImage>
                      <mainJar>RunProc-${project.version}.jar</mainJar>
                      <input>${assembly.location}/lib</input>
                      <destination>${deployment.location}</destination>
                      <type>APP_IMAGE</type>
      <temp>${assembly.location}/tempfiles</temp>
                  </configuration>

      </plugin>
      </plugins>
        </build>
        
        <dependencies>
      <dependency>
      <groupId>com.<USERNAME></groupId>
      <artifactId>RunProc</artifactId>
      <version>${project.version}</version>
      </dependency>
        </dependencies>
      </project>

      ======================================================

      RunProc/src/main/java/com/<USERNAME>/Go.java (RunProc executable class):

      package com.<USERNAME>;

      public class Go {

      public static void main(String[] args) {
      ProcessBuilder pb;

      pb = new ProcessBuilder(args);

      try {
      pb.start();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              asemenyuk Alexey Semenyuk
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: