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:
- With Java 8 java.library.path contains the value specified in the LibraryPath
- 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:
- Stackoverflow: Program uses outdated (not current) env variable value
- Microsoft Docs: Potential Errors Passing CRT Objects Across DLL Boundaries#This example passes environment variables across a DLL boundary
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.
.. 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.
TOMEE-2505 Update Commons Daemon for improved Java 11 support
DAEMON-390 PATH environment variable is not properly set if using LibraryPath option
- relates to
DAEMON-398 Java 11 jvm.dll startup messages not available on stdout/stderr using Windows 10/2016
- links to