打包后,在如下目录:
这里打包的springboot的jar文件名为 api-0.0.1-SNAPSHOT.jar
新建一个start.bat文件,start.bat文件的内容如下:
cd %~dp0
c:jdkjdk1.8.0_181injava.exe -dfile.encoding=utf-8 -jar api-0.0.1-snapshot.jar --server.port=81
cd %~dp0 表示切换到bat所在的目录下
-Dfile.encoding=utf-8 设置编码
--server.port=81 设置springboot访问端口为81
假设api-0.0.1-SNAPSHOT.jar和start.bat文件,都放在d:pidemo目录下
双击start.bat文件,会自动弹出控制台,信息大致如下:
D:pidemo>cd D:pidemo
D:pidemo>C:jdkjdk1.8.0_181injava.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.392 INFO 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:pidemopi-0.0.1-SNAPSHOT.jar started by Ad
ministrator in D:pidemo)
2021-06-19 16:28:33.392 INFO 4436 --- [ main] com.demo.api.ApiApp
lication : No active profile set, falling back to default profiles: def
ault
2021-06-19 16:28:37.236 INFO 4436 --- [ main] o.s.b.w.embedded.tomcat
.TomcatWebServer : Tomcat initialized with port(s): 81 (http)
2021-06-19 16:28:37.298 INFO 4436 --- [ main] o.apache.catalina.core.
StandardService : Starting service [Tomcat]
2021-06-19 16:28:37.298 INFO 4436 --- [ main] org.apache.catalina.cor
e.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-06-19 16:28:37.454 INFO 4436 --- [ main] o.a.c.c.C.[Tomcat].[loc
alhost].[/] : Initializing Spring embedded WebApplicationContext
2021-06-19 16:28:37.470 INFO 4436 --- [ main] w.s.c.ServletWebServerA
pplicationContext : Root WebApplicationContext: initialization completed in 3891
ms
2021-06-19 16:28:38.064 INFO 4436 --- [ main] o.s.s.concurrent.Thread
PoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-06-19 16:28:38.626 INFO 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.642 INFO 4436 --- [ main] com.demo.api.ApiApp
lication : Started ApiApplication in 6.504 seconds (JVM running for 7.7
85)
【现象】
【解决方法】
start.bat文件的编码设置为UTF-8,下面以Notepad++举例说明
【解决后效果】
【现象】
D:pidemo>锘縞d D:pidemo
'锘縞d' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
【解决方法】
start.bat中有其他符合,在Notepad++重新敲一下命令,或者切换一下编码。
【解决后的效果】
D:pidemo>cd D:pidemo
以上就是怎么使用bat启动springboot项目的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号