I need to write a batch script to find out if Java is installed, and if it is, then under what path? I feel it has to be something similar to this:
for /f %%j in ("java.exe") do (
set JAVA_HOME=..........
)
but I can not figure it out.
P.S. It has to work with path with spaces two. Like if java is installed into "Program Files".
Thanks.
Open command prompt and enter “java –version”. If installed version number is displayed. 2. On Windows, Java is usually installed in the directory C:/Program Files/Java.
Open a Command Prompt window (Win⊞ + R, type cmd, hit Enter). Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder.
Check the Java Version Using the Command Line First, click on the magnifying glass and type “cmd”, then click on the Command Line app icon that appears. Now, enter the command java -version and you'll see the version of Java listed.
Command Prompt Open CMD and search java -version.
Using reg[.exe] you can query possible JRE candidates that are installed on the system. There could be none or could be several.
On a test set-up, running inside the command shell:
reg query "HKLM\Software\JavaSoft\Java Runtime Environment"
I get three result lines, of which the first is
CurrentVersion REG_SZ 1.6
Based on that, querying
reg query "HKLM\Software\JavaSoft\Java Runtime Environment\1.6\"
Gives me JavaHome REG_SZ C:\Program Files\Java\jre6
It's much more efficient than scan a file system to find a java binary.
This was tested under a virtual installation of Windows XP 32-bit.
Couldn't you use the 'where' command? As in:
>where java
And test against this?
Example:
C:\Users\myname>where java
C:\Program Files (x86)\Java\jdk1.6.0_17\bin\java.exe
C:\Users\myname>where foo
INFO: Could not find files for the given pattern(s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With