Uploaded image for project: 'Commons Daemon'
  1. Commons Daemon
  2. DAEMON-396

LibraryPath is broken for Java 11 using Windows 10/2016

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.1.1
    • Component/s: Procrun
    • Labels:
      None

      Description

      My application which runs on TomEE is broken when running on Java 11 with Windows 10/2016. I'm getting this error:

      java.lang.UnsatisfiedLinkError: no xmlForJava in java.library.path: [C:\Program Files\TomEE\bin, <<more paths here>>, .]
                      at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
                      at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
                      at java.base/java.lang.System.loadLibrary(System.java:1867)
      

      It works for Java 8 and 10, but fails for both Oracle JDK 11 and OpenJDK 11.

      The application installs the service with the -LibraryPath option and -StartMode jvm. When inspecting the java.library.path using JMX, I observe this:

      1. With Java 8 java.library.path contains the value specified in the LibraryPath
      2. With Java 11 java.library.path contains the value of the PATH environment variable

      From the sourcecode I see that procrun is executing code in this order:

      _wputenv("PATH=;C:\\application\\lib");
      LoadLibraryW("jvm.dll")
      JNI_CreateJavaVM()
      SetDllDirectoryW(";C:\\application\\lib")
      

      The JVM is supposed to take the value of the PATH variable into account when loaded, but it doesn't.
      I found these articles:

      So the C-Runtime library has its own copy of the environment variables and behavior depends on how the binaries are compiled.

      • /MD means they share a single copy of the C-Runtime library.
      • /MT means that they use separate copies of the C-Runtime library.

      I expect that Java 11 is build differently, which causes this bug.

      Give this quote...

      Normally when Java is launched and a library path is not specified, the JVM will default to using the system PATH on Windows and the LD_LIBRARY_PATH on UNIX systems to locate any native libraries loaded by the application. This is akin to what happens with the CLASSPATH environment variable when a specific classpath is not specified when launching the JVM. The use of the CLASSPATH environment variable has fallen out of style because of all the conflict problems which can arise when multiple Java applications are installed on the same machine. The same issues are all there with the library path as well.
      In general, it is advised that you avoid potential problems when your application is deployed by being conservative about which directories will be included in the Java library path.
      https://wrapper.tanukisoftware.com/doc/english/prop-java-library-path-append-system-path.html

      .. I think it would be better to change the implementation of --LibraryPath to set the JVM option -Djava.library.path instead of the PATH env var.
      This will make procrun independent of how the jvm.dll is build.

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              gerwin84 Gerwin

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment