So, for a project I am working on, I need to find out where a javaw.exe
is located on a user's machine. How do I do that? Assuming that user is on Windows machine
The method that I used is limited to English versions of Windows only.
I looked for where the OS is installed, locate the Program Files
directory, locate Java
, jdk
directory, bin
, then javaw.exe
. I know this will not work on non-English versions of Windows.
What is the human-language-independent way to do this ?
Open a cmd shell,
cd \\
dir javaw.exe /s
To find "javaw.exe" in windows I would use (using batch)
for /f tokens^=2^ delims^=^" %%i in ('reg query HKEY_CLASSES_ROOT\jarfile\shell\open\command /ve') do set JAVAW_PATH=%%i
It should work in Windows XP and Seven, for JRE 1.6 and 1.7. Should catch the latest installed version.
It worked to me:
String javaHome = System.getProperty("java.home");
File f = new File(javaHome);
f = new File(f, "bin");
f = new File(f, "javaw.exe"); //or f = new File(f, "javaws.exe"); //work too
System.out.println(f + " exists: " + f.exists());
Try this
for %i in (javaw.exe) do @echo. %~$PATH:i
Source: Stackoverflow.com