What would be the best way to get the location of java.home in my C++ app? Right now I'm getting it from the registry but am wondering if there's a better/easier/cleaner way.
Thanks, Serge
What would be the best way to get the location of java.home in my C++ app? Right now I'm getting it from the registry but am wondering if there's a better/easier/cleaner way.
Thanks, Serge
if JAVA_HOME is set to the java home directory. If not val will be null.
char* val = getenv("JAVA_HOME"
);
If you're on a Unix/Linux box, perhaps you could do "which java". If you need assistance doing this in C++, see How to execute a command and get output of command within C++ using POSIX?
If you're on a Windows box, there is a "which.bat" someone made that I've used with success in the past, although it's not as good. You'd have to google for it.
Hopefully this can point you in the right direction!
There is often a copy of javaw in the System32 directory of a Windows installation, so getenv("windir")
, and concatenate "\System32\javaw.exe"
.
The second choice is then to open a File Browser dialog to choose the location of javaw.exe.