Find Java home

  • Print

This sample Lua code shows how you can locate the Java Runtime Environment's home folder.

 
function FindJavaHome()
  -- locate Java home folder
  local sJavaHome = "";
  local sCurrentVersion = Registry.GetValue(HKEY_LOCAL_MACHINE, 
    "Software\\JavaSoft\\Java Runtime Environment", "CurrentVersion");
  if (sCurrentVersion ~= "") then
    sJavaHome = Registry.GetValue(HKEY_LOCAL_MACHINE, 
      "Software\\JavaSoft\\Java Runtime Environment\\"..sCurrentVersion, "JavaHome");
  end
  return sJavaHome;
end
 
sJavaHome = FindJavaHome();
if (sJavaHome == "") then
  Dialog.Message("Error", "Java Runtime Environment could not be located.", MB_OK, 
    MB_ICONSTOP);
else
  Dialog.Message("Info", "The home folder of the JRE is " .. sJavaHome, MB_OK, 
    MB_ICONINFORMATION);
  if File.DoesExist(sJavaHome .. "\\bin\\java.exe") then
    Dialog.Message("Info", "Java.exe was found in " .. sJavaHome .. "\\bin", MB_OK,
      MB_ICONINFORMATION);
  else
    Dialog.Message("Error", "Java.exe was not found.", MB_OK, MB_ICONSTOP);
  end
end
 
 

Add a comment (For questions, please use the contact form!)

Security code
Refresh

Our Plugins & Examples Feed

  • Dependency module for Setup Factory: Visual C/C++ 2010 SP1

    New dependency modules to add runtime support for applications developed with Microsoft Visual C/C++ 2010...

  • LuaFileSystem 1.5.0 for AutoPlay Media Studio 8

    LuaFileSystem is a Lua library developed to complement the set of functions related to...

Subscribe now!

Do you need help?

clockWe provide customer support for Indigo Rose software development products since 2008!
Please contact us if you need assistance for designing, debugging, or finishing your project on time.