JDK-8267598 : jpackage removes system libraries from java.library.path
  • Type: Bug
  • Component: tools
  • Sub-Component: jpackage
  • Affected Version: 17
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-05-23
  • Updated: 2021-07-22
  • Resolved: 2021-06-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b26Fixed
Related Reports
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10

A DESCRIPTION OF THE PROBLEM :
EXE launchers created by jpackage don't have Windows system DLLs in java.library.path and sets the path to match the current installation directory and its "app" subdirectory - so System.loadLibrary("ole32") will fail. If setting -Djava.library.path explicitly when launching  jpackage, then jpackage does not append those two directories to java.library.path.

REGRESSION : Last worked in version 16.0.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use jpackage to generate launcher test.exe for the example program below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should have java.library.path such that is compatible for loading Windows system DLLs.
ACTUAL -
In JDK16 jpackage, the test program performs System.loadLibrary() for "ole32", "user32", "advapi32","shell32","kernel32": 
   System.getProperty("java.library.path") => ... long list including "C:\Program Files\APPNAME;C:\WINDOWS\system32;"
In JDK17 EA - the result is:
java.lang.UnsatisfiedLinkError: no ole32 in java.library.path: C:\Program Files\Duncan Panama\app;C:\Program Files\Duncan Panama


---------- BEGIN SOURCE ----------
package duncan.panama.screensaver;

import java.util.Arrays;

/**
 * Test issues with command line launch after using jpackage.
 * <p>Build a launcher for this class as test.exe and copy to test.scr
 */
public class Test
{
    public static void main(String[] args)
    {
        System.out.println("Application args: "+Arrays.toString(args));

        try {
            String[] props = new String[]{"jpackage.app-path", "java.library.path"};
            for (String prop : props) {
                System.out.println("System.getProperty(\""+prop+"\") => "+System.getProperty(prop));
            }

            String[] libs = new String[]{"ole32", "user32", "advapi32","shell32","kernel32"};
            for (String lib : libs) {
                System.out.println("System.loadLibrary(\""+lib+"\")");
                System.loadLibrary(lib);
            }
        } catch(Throwable t) {
            System.err.println("*** System load library FAILED *** "+ t.toString());
            t.printStackTrace();
        }
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
jpackage can be run with additional --java-options settings: "-Djava.library.path=c:\\Windows\\System32;C:\Program Files\APPNAME\appC:\Program Files\APPNAME" but this hardcodes the developers Windows PC %SYSTEMROOT% and anticipated installation directory into the installer EXE - these values may match the  target Windows PC.


FREQUENCY : always



Comments
The submitter confirmed that the issue is fixed.
21-06-2021

Requested the submitter to check if the fix solves the problem. The latest JDK 17 can be dowloaded from https://jdk.java.net/17/
07-06-2021

Changeset: af3df630 Author: Andy Herrick <herrick@openjdk.org> Date: 2021-06-03 19:02:11 +0000 URL: https://git.openjdk.java.net/jdk/commit/af3df6300efddc8ba12f095b87205cc2fea1f1e8
03-06-2021

We add APPDIR to the env variable (PATH, LD_LIBRARY_PATH, or DYLD_LIBRARY_PATH depending on platform) instead of setting -Djava.library.path. review: https://github.com/openjdk/jdk/pull/4203
03-06-2021

The default value of java.library.path (Which is what was used before the fix to JDK-8263157) is platform dependent and based on existing environment variables at runtime: On Windows, it is based on PATH env variable On Linux, it is based on LD_LIBRARY_PATH env variable On OS X, it based on DYLD_LIBRARY_PATH env variable. so unless there is another way to set additional paths without clearing the default ones we may need to read the platform dependent env variables and add that value to the -Djava.library.path setting the native launcher uses when launching jni.
25-05-2021

Appears to be a regression caused by fix to JDK-8263157 after that fix "-Djava.library.path=..." is added to application launcher, with the intention of adding the bundles "bin" dir and "app" dir to the path, but change also results in removing the default java.library.path setting(s)
25-05-2021

I used the following command to reproduce the issue: jpackage --verbose --win-console --input i --dest o --name Main --main-jar Main.jar --main-class Main The issue is reproducible with JDK 17: Application args: [] System.getProperty("jpackage.app-path") => C:\Program Files\Main\Main.exe System.getProperty("java.library.path") => C:\Program Files\Main\app;C:\Program Files\Main System.loadLibrary("ole32") *** System load library FAILED *** java.lang.UnsatisfiedLinkError: no ole32 in java.library.path: C:\Program Files\Main\app;C:\Program Files\Main java.lang.UnsatisfiedLinkError: no ole32 in java.library.path: C:\Program Files\Main\app;C:\Program Files\Main at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source) at java.base/java.lang.Runtime.loadLibrary0(Unknown Source) at java.base/java.lang.System.loadLibrary(Unknown Source) at Main.main(Main.java:17)
24-05-2021

After going through different builds, following is my observation: JDK 17 b10: Pass JDK 17 b15: Pass JDK 17 b17: Pass JDK 17 b18: Fail JDK 17 b19: Fail JDK 17 b20: Fail JDK 17 b21: Fail JDK 17 b22: Fail JDK 17 b23: Fail This is a regression issue.
24-05-2021

Additional information from the submitter ================================= jpackage provides macros / variables $APPDIR and $BINDIR so the workaround does not need to hardcode the target installation directory. Therefore where I said workaround is to add: --java-options "-Djava.library.path=c:\\Windows\\System32;C:\Program Files\APPNAME\appC:\Program Files\APPNAME it can be become (assuming developer needs APPDIR / BINDIR is the packaged application library path): -java-options "-Djava.library.path=c:\\Windows\\System32;$APPDIR;$BINDIR" However there isn't an easy way to substitute the value of %SYSTEMROOT%\\System32 for the target Windows PC.
24-05-2021