Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if JAVA_HOME is present in environment using batch script

I want to check whether JAVA_HOME is present in environment or not So I wrote the below script a.bat

if "%JAVA_HOME%" == "" 
(
echo Enter path to JAVA_HOME: 
set /p javahome=
)
if not "%JAVA_HOME%" == ""
(
echo %JAVA_HOME%
)

It shows "The syntax of the command is incorrect" where am i going wrong?

like image 501
AabinGunz Avatar asked Aug 11 '11 06:08

AabinGunz


People also ask

How do you check if JAVA_HOME is set or not?

Verify JAVA_HOME 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. If it doesn't, your JAVA_HOME variable was not set correctly.

How do you check Java is installed or not in batch file?

Try using java -version command in your script and saving it to a variable like this: isJavaInstalled="$(java -version)" . If Java is installed, the variable should contain something like this: java version "1.8. 0_131" Java(TM) SE Runtime Environment (build 1.8.

How do I know if my house is JRE?

Click the Advanced tab, and then click Environment Variables. Under System Variables, look for the JAVA_HOME system variable. The JAVA_HOME path should point to the location that you recorded when you installed the JRE.

What does %% mean in batch script?

%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt.


1 Answers

Try this:

@echo off
IF "%JAVA_HOME%" == "" (
    echo Enter path to JAVA_HOME: 
    set /p JAVA_HOME=
) ELSE (
    echo %JAVA_HOME%
)
like image 118
dertkw Avatar answered Oct 18 '22 10:10

dertkw