I’m making a small launcher program for my Java program, the idea being that i can set memory requirements, associated libraries, and stuff like that before calling Java.
However, i’m increasingly finding that there doesn’t seem to be a set-in-stone way to call Java from ANYTHING.
- It is no longer the case that there’s a java.exe in system32, so that’s not guaranteed.
- On most computers there’s a registry entry either under HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER that defines a JRE subkey, then a JavaHome value. That works on most computers, but on my new computer (fresh java install, built less than two weeks ago) these registries don’t exist. There’s a JRE entry in CURRENT_USER, but no JavaHome.
- The JAVA_HOME environment variable isn’t always set, or set correctly. Specifically on machines that don’t have the JDK installed.
- I obviously can’t rely on Java being installed to C:/Program Files/Java.
How the bleep am i supposed to be able to call a java program reliably from a C++ one? Or for that matter, from anywhere? I could have my program try all four possible methods, but what if they come up empty?
Thanks in advance.
First, finding the JRE location, setting memory requirements and stuff like that is highly recommended to implement using one of available scripting languages. Due to the language of BAT files is relatively poor you can use VBS or JScript and run them using utility named
cscript.Concerning to the fact where JRE is.
Typically JRE can be found in registry. For example on my machine I can see the following entry.
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6.0_26Probably you have newer installation… Anyway check entry for Java installation here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\UninstallIn my case I have there entry
{26A24AE4-039D-4CA4-87B4-2F83216012FF}where key namedInstallLocationcontains path to Java Home.The next way is to check Java home environment variable.
The last way is to perform search in %ProgramFiles%