Windows batch file - check if JAVA_HOME contains java 7
batch-file, java, java-7, windows
Solution
Since you have tagged your question as batch-file, I assume you want to do this in a batch file.
Batch file to check this
@echo off
"%JAVA_HOME%"\bin\java -version:1.7 -version > nul 2>&1
if %ERRORLEVEL% == 0 goto found
echo NOT FOUND
goto end
:found
echo FOUND
:end
I have just made the batch file print FOUND if the java in %JAVA_HOME% is java 7 or print NOT FOUND if it's not java 7. You can tweak the batch file for your needs.
java -version:1.7 returns a success(0) to the shell if it's java 7. Else it returns a failure (non-zero). You can use `ERRORLEVEL` to check the return value and determine what the previous command returned.
Problem
Is there a way to determine in a windows batch file if a `JAVA_HOME` environment system variable contains Java 7?