How to get JRE path from C, CPP applications?
The JNI_CreateJavaVM fails at runtime because it doesn't get correct JRE path.
Can anybody help me get the ways to get correct JRE path at runtime?
Do I have to read any registry entries for this?
Are there any ENVIRONMENT variables set for this?
Do I've to hard-code it?
Any pointers are helpful
Thanks in advance,
a1prashant
On Windows you should use the registry.
You should read the sting value of "CurrentVersion"
of the key (HKEY_LOCAL_MACHINE, "SOFTWARE\JavaSoft\Java Runtime Environment")
Then use it to read the string value of "RuntimeLib"
of the sub-key specified by "CurrentVersion".
This gives you the location of jvm.dll.
Eg.:HKEY_LOCAL_MACHINE
SOFTWARE
JavaSoft
Java Runtime Environment
CurrentVersion = "1.5"
HKEY_LOCAL_MACHINE
SOFTWARE
JavaSoft
Java Runtime Environment
1.5
RuntimeLib = "C:\Program Files\Java\jre1.5.0_08\bin\client\jvm.dll"
You should have a look at java_md.c file located in the src.zip file that comes with your Sun jdk
(look for the GetPublicJREHome function to learn how to search the registry programmatically).
Regards