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.
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_26
Probably you have newer installation... Anyway check entry for Java installation here: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
In my case I have there entry {26A24AE4-039D-4CA4-87B4-2F83216012FF}
where key named InstallLocation
contains path to Java Home.
The next way is to check Java home environment variable.
The last way is to perform search in %ProgramFiles%
In your installer try all methods, maybe you find more than one JRE, maybe none. Then present detected JREs and allow selecting which user want to use. User can also point JRE, especially when installer did not find it.
Eclipse uses a C shim (eclipse.exe) to spawn a JVM. You might to take a look at that source code and adapt.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.