批处理脚本检查Java家庭和比较Java版本

您好我需要一个批处理脚本来检查是否在系统和脚本中的Java家是可用的比较Java版本

我的要求是

1.)脚本需要检查系统中是否设置了java home。我认​​为“echo%JAVA_HOME%”会执行此操作。但是如果Java Home不可用,则需要显示一条消息,显示“Java home is not available.Please在“计算机”>“属性”>“variablespath”中设置Java主目录。

2.)需要检查系统中的java版本,如果java vesion高于1.6_445,则需要在“Java版本较高的MR工具将无法安装”的消息中插入(我认为这个它需要创build一个数组,并存储Java版本值,它需要比较值。但我不知道如何编写它的代码)由于Java版本包含下划线比较将是一个艰难的任务,我认为。

目前我正在使用下面的脚本,但是完全不能满足我的要求。任何人都可以帮我做一个脚本来满足上面的要求。

回声setlocal enableextensions disabledelayedexpansion

:: possible locations under HKLM\SOFTWARE of JavaSoft registry data set "javaNativeVersion=" set "java32ON64=Wow6432Node\" :: for variables :: %%k = HKLM\SOFTWARE subkeys where to search for JavaSoft key :: %%j = full path of "Java Runtime Environment" key under %%k :: %%v = current java version :: %%e = path to java set "javaDir=" set "javaVersion=" for %%k in ( "%javaNativeVersion%" "%java32ON64%") do if not defined javaDir ( for %%j in ( "HKLM\SOFTWARE\%%~kJavaSoft\Java Runtime Environment" ) do for /f "tokens=3" %%v in ( 'reg query "%%~j" /v "CurrentVersion" 2^>nul ^| find /i "CurrentVersion"' ) do for /f "tokens=2,*" %%d in ( 'reg query "%%~j\%%v" /v "JavaHome" 2^>nul ^| find /i "JavaHome"' ) do ( set "javaDir=%%~e" & set "javaVersion=%%v" ) ) if not defined javaDir ( echo Java not found ) else ( echo JAVA_HOME="%javaDir%" echo JAVA_VERSION="%javaVersion%" ) endlocal pause 

Solutions Collecting From Web of "批处理脚本检查Java家庭和比较Java版本"

  @echo off :: possible locations under HKLM\SOFTWARE of JavaSoft registry data set "javaNativeVersion=" set "java32ON64=Wow6432Node\" :: for variables :: %%k = HKLM\SOFTWARE subkeys where to search for JavaSoft key :: %%j = full path of "Java Runtime Environment" key under %%k :: %%v = current java version :: %%e = path to java set "javaDir=" set "javaVersion=" for %%k in ( "%javaNativeVersion%" "%java32ON64%") do if not defined javaDir ( for %%j in ("HKLM\SOFTWARE\%%~kJavaSoft\Java Runtime Environment" ) do for /f "tokens=3" %%v in ( 'reg query "%%~j" /v "CurrentVersion" 2^>nul ^| find /i "CurrentVersion"' ) do for /f "tokens=2,*" %%d in ( 'reg query "%%~j\%%v" /v "JavaHome" 2^>nul ^| find /i "JavaHome"' ) do ( set "javaDir=%%~e" & set "javaVersion=%%v" ) ) if not defined javaDir ( echo Java not found exit /b 1 ) else ( echo JAVA_HOME=%javaDir% set JAVA_HOME=%javaDir% PATH %JAVA_HOME%\bin;%PATH% java.exe >nul 2>&1 || ( setx JAVA_HOME %JAVA_HOME% setx PATH %PATH% ) echo JAVA_VERSION=%javaVersion% ) for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do @set "jver=%%j%%k%%l%%m" echo full java version %jver% if %jver% GTR 16445 ( echo "Java version is higher MR tool will not able to install" exit /b 2 )