I am running Windows 7 64bit, and Java 1.8. When I try to call JNI_CreateJavaVM the program exits. It does not "crash", is actually calls exit(). (!!)
I have already researched, and found these other discussions:
Invoking Java from C++: how to catch/detect a fatal JVM error?
JNI_CreateJavaVM() terminates with exit code 1
They do not solve the problem.
So, if the environment isn't setup right, the program will just disappear. I am tasked with creating an app that must use a Java lib to execute. And if the users environment (which I have no control over) isn't set right, or is modified later, the program simply "goes away", where I have no ability to do any defensive coding!
What type of mental disorder was present when some Oracle guy thought this was a good idea??
Java installs itself and modifies the path with the the directory C:\PROGRAMDATA\ORACLE\JAVA\JAVAPATH... And in there are a bunch of shortcuts to the current version of Java ("C:\Program Files (x86)\Java\jre1.8.0_31\bin" in my case). If I have to modify the path to also point to the location of the JVM dll (which conveniently is NOT in the same location, but in a sub-directory) and later something updates Java and changes those shortcuts, the path will still point to the old DLL.
Has anyone found a way to accomplish this? I mean robustly? In other words, while still being a good programmer? Because the JNI/JVM environment is definitely trying to prevent you from doing so.
As for why it fails, all I did was move the DLL to my local folder. But apparently, it requires that there be other things relative to the location of the DLL.
So here;s another disorder in the way I see it working:
Pretend I wish to use a JVM that is in "jre1.8.0_31". But someone updated to jre1.10.0_xx. So the system is updated to use the new runtime, and the path is changed via the C:\PROGRAMDATA\ORACLE\JAVA\JAVAPATH shortcut. The JVM that I *want* to use is no longer in the path. – SpacemanScott Apr 12 '15 at 23:14