教你bat脚本一键配置java开发环境
背景
在新电脑配置或者新人入职时需要对java开发相关环境进行配置安装,但时常会因为安装配置不到位或者操作错误导致时间的浪费,所以在空余时间收集了一系列软件的免安装版本,并且编写了相关配置脚本,让环境安装变得标准化。
概览
安装包目录如下如所示
文章图片
BaseEnv包含jdk(1.8),maven(3.2.5)
ProgramEnv包含idea(2019.2)
SoftEnv包含mysql(5.7),navicat(15),redis,redismanage(1.5.8)
remark为安装总说明
setting.bat脚本配置环境变量
mysql.bat脚本安装mysql服务
redis.bat脚本安装redis服务
icon脚本在桌面创建软件快捷方式
上述软件可以基本满足日常java开发的环境要求
安装包百度网盘地址:环境变量脚本 环境变量脚本可以通过wmic ENVIRONMENT语句进行删除重新重新创建,Path变量的变更可以通过get
链接: https://pan.baidu.com/s/19WIgCkSgw7Sn71FDkWZRIw 提取码: kbf6
VariableValue|findstr /i语句进行判断是否存在,bat脚本可以获取当前路径动态的去进行配置,免去了手动
输入的繁琐步骤,脚本如下
@echo offcolor 02:step1cd /d %~dp0set currentPath=%PATH%set currentDir=%cd%set javaPath=%currentDir%\BaseEnv\jdkset mavenPath=%currentDir%\BaseEnv\mavenset mysqlPath=%currentDir%\SoftEnv\mysqlset redisPath=%currentDir%\SoftEnv\redis:step2wmic ENVIRONMENT where "name='JAVA_HOME'" deletewmic ENVIRONMENT create name="JAVA_HOME",username="",VariableValue="https://www.it610.com/article/%javaPath%"wmic ENVIRONMENT where "name='MAVEN_HOME'" deletewmic ENVIRONMENT create name="MAVEN_HOME",username="",VariableValue="https://www.it610.com/article/%mavenPath%"wmic ENVIRONMENT where "name='CLASSPATH'" deletewmic ENVIRONMENT create name="CLASSPATH",username="",VariableValue="https://www.it610.com/article/.; %%JAVA_HOME%%/lib/toos.jar; %%JAVA_HOME%%/lib/dt.jar"wmic ENVIRONMENT where "name='MYSQL_HOME'" deletewmic ENVIRONMENT create name="MYSQL_HOME",username="",VariableValue="https://www.it610.com/article/%mysqlPath%"wmic ENVIRONMENT where "name='REDIS_HOME'" deletewmic ENVIRONMENT create name="REDIS_HOME",username="",VariableValue="https://www.it610.com/article/%redisPath%"echo.goto step3:step3wmic ENVIRONMENT where "name='Path'" get VariableValue|findstr /i /c:"%%JAVA_HOME%%\bin">nul&&(goto step5)echo PATH环境变量中未添加: %%JAVA_HOME%%\bin wmic ENVIRONMENT where "name='Path' and username=''" set VariableValue="https://www.it610.com/article/%currentPATH%; %%JAVA_HOME%%/bin"set currentPATH=%currentPATH%; %%JAVA_HOME%%\binecho.:step5echo JAVA_HOME PATH中已添加wmic ENVIRONMENT where "name='Path'" get VariableValue|findstr /i /c:"%%MAVEN_HOME%%\bin">nul&&(goto step6)echo PATH环境变量中未添加: %%MAVEN_HOME%%\bin wmic ENVIRONMENT where "name='Path' and username=''" set VariableValue="https://www.it610.com/article/%currentPATH%; %%MAVEN_HOME%%/bin"set currentPATH=%currentPATH%; %%MAVEN_HOME%%\binecho.:step6echo MYSQL_HOME PATH中已添加wmic ENVIRONMENT where "name='Path'" get VariableValue|findstr /i /c:"%%MYSQL_HOME%%\bin">nul&&(goto step7)echo PATH环境变量中未添加: %%MYSQL_HOME%%\bin wmic ENVIRONMENT where "name='Path' and username=''" set VariableValue="https://www.it610.com/article/%currentPATH%; %%MYSQL_HOME%%/bin"set currentPATH=%currentPATH%; %%MYSQL_HOME%%\binecho.:step7echo MYSQL PATH中已添加wmic ENVIRONMENT where "name='Path'" get VariableValue|findstr /i /c:"%%REDIS_HOME%%">nul&&(goto step8)echo PATH环境变量中未添加: %%REDIS_HOME%%wmic ENVIRONMENT where "name='Path' and username=''" set VariableValue="https://www.it610.com/article/%currentPATH%; %%REDIS_HOME%%"echo.:step8echo REDIS PATH中已添加pause
服务安装脚本 redis通过--service-install语句进行windows服务的安装
@echo offcolor 02"%cd%\SoftEnv\redis\redis-server.exe"--service-install %cd%\SoftEnv\redis\redis.windows.conf net start Redispause
mysql通过--initialize-insecure语句进行windows服务的安装
@echo offcolor 02"%cd%\SoftEnv\mysql\bin\mysqld.exe" --install mysql --defaults-file="%cd%\SoftEnv\mysql\my.ini""%cd%\SoftEnv\mysql\bin\mysqld.exe" --initialize-insecure --user=mysqlnet start mysqlpause
快捷方式创建脚本 通过WshShell脚本的方式进行图标快捷方式的创建
@echo offset currentDir=%cd%set Program=%cd%\ProgramEnv\idea\bin\idea64.exeset LnkName=ideaset WorkDir=set Desc=ideaif not defined WorkDir call:GetWorkDir "%Program%"(echo Set WshShell=CreateObject("WScript.Shell"^)echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\%LnkName%.lnk"^)echo oShellLink.TargetPath="%Program%"echo oShellLink.WorkingDirectory="%WorkDir%"echo oShellLink.WindowStyle=1echo oShellLink.Description="%Desc%"echo oShellLink.Save)>makelnk.vbsecho idea icon link set success!makelnk.vbsset Program=%cd%\SoftEnv\navicat\navicat.exeset LnkName=navicatset WorkDir=set Desc=navicatif not defined WorkDir call:GetWorkDir "%Program%"(echo Set WshShell=CreateObject("WScript.Shell"^)echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\%LnkName%.lnk"^)echo oShellLink.TargetPath="%Program%"echo oShellLink.WorkingDirectory="%WorkDir%"echo oShellLink.WindowStyle=1echo oShellLink.Description="%Desc%"echo oShellLink.Save)>makelnk.vbsecho navicat icon link set success!makelnk.vbsset Program=%cd%\SoftEnv\redismanage\rdm.exeset LnkName=rdmset WorkDir=set Desc=rdmif not defined WorkDir call:GetWorkDir "%Program%"(echo Set WshShell=CreateObject("WScript.Shell"^)echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\%LnkName%.lnk"^)echo oShellLink.TargetPath="%Program%"echo oShellLink.WorkingDirectory="%WorkDir%"echo oShellLink.WindowStyle=1echo oShellLink.Description="%Desc%"echo oShellLink.Save)>makelnk.vbsecho rdm icon link set success!makelnk.vbsdel /f /q makelnk.vbsexitgoto :eof:GetWorkDirset WorkDir=%~dp1set WorkDir=%WorkDir:~,-1%goto :eof
【教你bat脚本一键配置java开发环境】到此这篇关于bat脚本一键配置java开发环境的文章就介绍到这了,更多相关bat脚本一键配置java环境内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 《手把手教你》系列基础篇(七十七)-java+|《手把手教你》系列基础篇(七十七)-java+ selenium自动化测试-框架设计基础-TestNG依赖测试- 上篇(详解教程)
- 求职特训营火热来袭|求职特训营火热来袭 阿里大咖教你制作专业简历
- 一文教你MySQL如何优化无索引的join
- MyBatisPlus代码生成器的使用示例
- Mybatis|Mybatis Plus 中的LambdaQueryWrapper示例详解
- Java毕业设计项目实战篇|Java项目:在线点餐系统(java+Springboot+Maven+mybatis+Vue+mysql+Redis)
- Linux开机自启应用&开机执行脚本&监听端口应用挂掉了执行启动脚本
- Vite 实战(手把手教你写一个 Vite 插件)
- springboot+mybatis报错找不到实体类的问题
- 求职特训营火热来袭,阿里大咖教你制作专业简历