Bat ·

一键设置JAVA环境脚本bat

下面这个cmd命令使用方法,一、先安装 JDK 然后在运行这个bat,如果运行时无法设置环境变量,请把这个

bat放到 jdk安装目录里,在运行这个bat工具

@echo offtitle Java环境变量设置 - Script by. fooher.comif "%~1"=="j" start "" "%0"&&exitclscolor 0aecho 注意:echo.echo 先安装Java JDK后再运行此脚本,echo.echo 如果无法从注册表读取路径,echo.echo 请手动将此脚本放在Java\jdk1.7.0\目录下运行echo.echo JAVA默认安装目录一般是在C:\Program Files\Java\jdk1.7.0\echo.echo 请根据实际情况放置。fooher.com QQ:201657139echo.echo =============================================================cd /d "%~dp0"for /f "usebackq tokens=1,2,* delims= " %%i in (`%windir%\system32\REG.exe QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit" /v CurrentVersion`) do set "JavaVersion=%%k"for /f "usebackq tokens=1,2,* delims= " %%i in (`%windir%\system32\REG.exe QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\%JavaVersion%" /v JavaHome`) do set "JavaHome=%%k"if not exist "%JavaHome%\bin\java.exe" set "JavaHome=%cd%"if not exist "%JavaHome%\bin\java.exe" (echo.&echo 注册表读取JAVA安装路径失败~请手动放入正确目录后再次运行脚本吧~&pause>nul&&exit) else (echo.&echo JAVA安装目录读取正常!)echo.echo "%JavaHome%"echo.set /p "I=是否继续设置环境变量?(Y/N) "if /i not "%I%"=="Y" exitclsecho ^>^>^>JAVA_HOME...if /i not "%JAVA_HOME%"=="%JavaHome%" ( "%windir%\system32\setx.exe" JAVA_HOME "%JavaHome%" -m) else echo.&&echo JAVA_HOME 已存在,并且正常。echo.&echo ^>^>^>CLASSPATH...if /i not "%CLASSPATH%"=="%JAVA_HOME%\lib" ( "%windir%\system32\setx.exe" CLASSPATH "%%JAVA_HOME%%\lib" -m) else echo.&&echo CLASSPATH 已存在,并且正常。set "tPath=%Path%"echo.echo ^>^>^>Path ~ 1...echo %tPath%|"%windir%\system32\find.exe" /i "%JavaHome%\bin" >nul||"%windir%\system32\setx.exe" Path %%JAVA_HOME%%\bin;"%tPath%" -m&&set "tPath=%%JAVA_HOME%%\bin;%tPath%"&&goto jmp1echo.&echo "%JavaHome%\bin" 已存在。:jmp1echo.echo ^>^>^>Path ~ 2...echo %tPath%|"%windir%\system32\find.exe" /i "%JavaHome%\jre\bin" >nul||"%windir%\system32\setx.exe" Path %%JAVA_HOME%%\jre\bin;"%tPath%" -m&&goto jmp2echo.&echo "%JavaHome%\jre\bin" 已存在。:jmp2echo.echo =================================================echo.&echo 设置完成!谢谢使用! - By.fooher.com 运维天涯echo.&echo. 2009/10/28 2:56pause >nulgoto :eof

评论已关闭