使用bat安装jdk和配置环境变量

文件路径
image

@echo off
Setlocal enabledelayedexpansion
@REM vscode中自动开启延迟环境变量扩展, 

%~d0
cd %~dp0

@REM dir
echo 安装jdk --》这里仅安装jdk 不会安装附属jre
@REM dir
@REM start /wait "jdk-8u131-windows-x64.exe" /quiet
"jdk-8u131-windows-x64.exe" /quiet
@REM C:\Program Files\Java\jdk1.8.0_131

echo 提取系统级变量path
set key="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
for /F "skip=2 tokens=3" %%i IN ('reg query %key% /v "Path"') do (
echo 原始Path ======= %%i
set temppath=%%i
)

echo 设置jdk环境变量
setx /M JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131"

setx /M path "%temppath%%%JAVA_HOME%%\bin"

setx /M classpath ".;%%JAVA_HOME%%\lib\dt.jar;%%JAVA_HOME%%\lib\tools.jar"

pause
posted @ 2022-06-23 00:32  姬雨晨  阅读(527)  评论(0编辑  收藏  举报