复制代码
- @echo off
- title java环境变量配置
- color 0A
- echo.
- echo. ===================================================
- echo.
- echo 即将配置环境变量......
- echo.
- echo 确定(鼠标右击)以管理员方式打开
- echo.
- echo 配置Java,Maven环境
- echo.
- echo. ===================================================
- echo.
- echo 1 (配置Java环境变量)
- echo.
- echo 2 (配置Maven环境变量)
- echo.
- echo 3 (退出程序)
- echo.
- echo. ===================================================
- echo.
- SET /P ST= 请选择:
- echo.
- if /I "%ST%"=="1" goto javah
- if /I "%ST%"=="2" goto mavenh
- if /I "%ST%"=="3" goto exh
- echo 无效选择,按任意键退出!
- pause >nul
- exit
- :javah
- echo JAVA_HOME
- echo %JAVA_HOME%
- if defined JAVA_HOME (echo 已经存在JAVA_HOME配置!继续设置输入1) else (goto setjavah)
- SET /P javainput= 请选择:
- if /I "%javainput%"=="1" goto setjavah
- echo 按任意键退出!
- pause >nul
- exit
- :mavenh
- if defined MAVEN_HOME (echo 已经存在MAVEN_HOME配置!继续设置输入2) else (goto setmavenh)
- SET /P maveninput= 请选择:
- if /I "%maveninput%"=="2" goto setmavenh
- echo 按任意键退出!
- pause >nul
- exit
- :setjavah
- set /p "input=请输入java的jdk路径(或回车默认路径为C:\Program Files\Java\jdk1.8.0_311):"
- if defined input (echo jdk路径已设置) else (set input=C:\Program Files\Java\jdk1.8.0_311)
- echo jdk路径为%input%
- set javaPath=%input%
- ::如果有的话,先删除JAVA_HOME
- wmic ENVIRONMENT where "name='JAVA_HOME'" delete
- ::如果有的话,先删除ClASS_PATH
- wmic ENVIRONMENT where "name='CLASS_PATH'" delete
- ::创建JAVA_HOME
- wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%javaPath%"
- ::创建CLASS_PATH
- wmic ENVIRONMENT create name="CLASS_PATH",username="<system>",VariableValue=".;%%javaPath%%\lib\tools.jar;%%javaPath%%\lib\dt.jar;"
- ::在环境变量path中,剔除掉变量java_home中的字符,回显剩下的字符串
- call set xx=%Path%;%javaPath%\jre\bin;%javaPath%\bin
- echo %xx%
- ::将返回显的字符重新赋值到path中
- wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue="%xx%"
- goto setmessage
- :setmavenh
- set /p "minput=请输入Maven所在路径(或回车默认路径为E:\apache-maven-3.8.4):"
- if defined minput (echo Maven路径已设置) else (set minput=E:\apache-maven-3.8.4)
- echo Maven路径为%minput%
- set mavenPath=%minput%
- ::如果有的话,先删除MAVEN_HOME
- wmic ENVIRONMENT where "name='MAVEN_HOME'" delete
- ::创建MAVEN_HOME
- wmic ENVIRONMENT create name="MAVEN_HOME",username="<system>",VariableValue="%mavenPath%"
- ::在环境变量path中,剔除掉变量MAVEN_HOME中的字符,回显剩下的字符串
- call set xx=%Path%;%mavenPath%\bin
- echo %xx%
- echo %mavenPath%
- ::将返回显的字符重新赋值到path中
- wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue="%xx%"
- goto setmessage
- :setexist
- echo.
- echo 已经存在配置,按任意键退出!
- goto exh
- :setmessage
- echo.
- echo 配置完成,请重启,按任意键退出!
- goto exh
- :exh
- echo.
- echo. ===================================================
- echo.
- pause >nul
- exit
- pause
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |