使用bat启动springboot项目并解决乱码问题
目录
- 1.springboot项目打包jar
- 2.编写bat启动springboot脚本
- 3.bat启动springboot
- 4.常见问题
- 4.1.解决bat控制台中文乱码问题
- 4.2.cd %~dp0不是内部或外部命令
1.springboot项目打包jar
![使用bat启动springboot项目并解决乱码问题](https://img.it610.com/image/info11/d3ae7a5eab014d5c9e93e4a74401611c.jpg)
文章图片
打包后,在如下目录:
![使用bat启动springboot项目并解决乱码问题](https://img.it610.com/image/info11/3db2cf8782094af2a57252eba19b6c23.jpg)
文章图片
这里打包的springboot的jar文件名为 api-0.0.1-SNAPSHOT.jar
2.编写bat启动springboot脚本 新建一个start.bat文件,start.bat文件的内容如下:
【使用bat启动springboot项目并解决乱码问题】cd %~dp0cd %~dp0 表示切换到bat所在的目录下
C:\jdk\jdk1.8.0_181\bin\java.exe -Dfile.encoding=utf-8 -jar api-0.0.1-SNAPSHOT.jar --server.port=81
-Dfile.encoding=utf-8 设置编码
--server.port=81 设置springboot访问端口为81
3.bat启动springboot 假设api-0.0.1-SNAPSHOT.jar和start.bat文件,都放在d:\apidemo目录下
双击start.bat文件,会自动弹出控制台,信息大致如下:
D:\apidemo>cd D:\apidemo\
D:\apidemo>C:\jdk\jdk1.8.0_181\bin\java.exe -Dfile.encoding=utf-8 -jar api-0.0.
1-SNAPSHOT.jar --server.port=81
._______ _ _
/\\ / ___'_ __ _ _(_)_ ____ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/___)| |_)| | | | | || (_| |) ) ) )
'|____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::(v2.4.3)
2021-06-19 16:28:33.392INFO 4436 --- [main] com.demo.api.ApiApp
lication: Starting ApiApplication v0.0.1-SNAPSHOT using Java 1.8.0_181
on iZ23lkhhnpiZ with PID 4436 (D:\apidemo\api-0.0.1-SNAPSHOT.jar started by Ad
ministrator in D:\apidemo)
2021-06-19 16:28:33.392INFO 4436 --- [main] com.demo.api.ApiApp
lication: No active profile set, falling back to default profiles: def
ault
2021-06-19 16:28:37.236INFO 4436 --- [main] o.s.b.w.embedded.tomcat
.TomcatWebServer: Tomcat initialized with port(s): 81 (http)
2021-06-19 16:28:37.298INFO 4436 --- [main] o.apache.catalina.core.
StandardService: Starting service [Tomcat]
2021-06-19 16:28:37.298INFO 4436 --- [main] org.apache.catalina.cor
e.StandardEngine: Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-06-19 16:28:37.454INFO 4436 --- [main] o.a.c.c.C.[Tomcat].[loc
alhost].[/]: Initializing Spring embedded WebApplicationContext
2021-06-19 16:28:37.470INFO 4436 --- [main] w.s.c.ServletWebServerA
pplicationContext : Root WebApplicationContext: initialization completed in 3891
ms
2021-06-19 16:28:38.064INFO 4436 --- [main] o.s.s.concurrent.Thread
PoolTaskExecutor: Initializing ExecutorService 'applicationTaskExecutor'
2021-06-19 16:28:38.626INFO 4436 --- [main] o.s.b.w.embedded.tomcat
.TomcatWebServer: Tomcat started on port(s): 81 (http) with context path ''
2021-06-19 16:28:38.642INFO 4436 --- [main] com.demo.api.ApiApp
lication: Started ApiApplication in 6.504 seconds (JVM running for 7.7
85)
4.常见问题
4.1.解决bat控制台中文乱码问题
【现象】
![使用bat启动springboot项目并解决乱码问题](https://img.it610.com/image/info11/2ca8cc7c8e5b49bda91807a09f416d30.png)
文章图片
【解决方法】
start.bat文件的编码设置为UTF-8,下面以Notepad++举例说明
![使用bat启动springboot项目并解决乱码问题](https://img.it610.com/image/info11/558ec99f79504176863b4e4d29fc1ee0.jpg)
文章图片
【解决后效果】
![使用bat启动springboot项目并解决乱码问题](https://img.it610.com/image/info11/f03c40a0f9d44f908d90aff234c16b50.png)
文章图片
4.2.cd %~dp0不是内部或外部命令
【现象】
D:\apidemo>锘縞d D:\apidemo\【解决方法】
'锘縞d' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
start.bat中有其他符合,在Notepad++重新敲一下命令,或者切换一下编码。
【解决后的效果】
D:\apidemo>cd D:\apidemo\到此这篇关于使用bat启动springboot项目并解决乱码问题的文章就介绍到这了,更多相关bat启动springboot项目内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 由浅入深理解AOP
- 【译】20个更有效地使用谷歌搜索的技巧
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- mybatisplus如何在xml的连表查询中使用queryWrapper
- mybatisplus|mybatisplus where QueryWrapper加括号嵌套查询方式
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- iOS中的Block
- Linux下面如何查看tomcat已经使用多少线程
- 使用composer自动加载类文件