My application which runs on TomEE is broken when running on Java 11 with Windows 10/2016. I'm getting this error:
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:
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.