Home  >  Article  >  Java  >  How to use bat to start springboot project

How to use bat to start springboot project

WBOY
WBOYforward
2023-05-14 13:34:062065browse

1.springboot project packaging jar

How to use bat to start springboot project

After packaging, in the following directory:

How to use bat to start springboot project

Springboot is packaged here The jar file name is api-0.0.1-SNAPSHOT.jar

2. Write bat to start springboot script

Create a new start.bat file. The content of the start.bat file is as follows:

cd %~dp0
C:\jdk\jdk1.8.0_181\bin\java.exe -Dfile.encoding=utf-8 -jar api-0.0.1-SNAPSHOT.jar -- server.port=81

cd %~dp0 means switching to the directory where bat is located

-Dfile.encoding=utf-8 Set encoding

-- server.port=81 Set the springboot access port to 81

3.bat starts springboot

Assume that the api-0.0.1-SNAPSHOT.jar and start.bat files are placed in d:\

Double-click the start.bat file in the apidemo directory, and the console will automatically pop up. The information is roughly as follows:

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.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:\apidemo\api-0.0.1-SNAPSHOT.jar started by Ad
ministrator in D:\apidemo)
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.c. [tomcat]. [LOC
Alhost]. [/]: Initializing Spring Embedded WebApplicontext
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)

4. Frequently Asked Questions

4.1. Solving the problem of Chinese garbled characters in the bat console

[Phenomena]

How to use bat to start springboot project

[Solution]

The encoding of the start.bat file is set to UTF-8. The following uses Notepad as an example

How to use bat to start springboot project

【Result after solution】

How to use bat to start springboot project

4.2.cd %~dp0 is not an internal or external command

[Phenomena]

D:\apidemo>锘缟d D :\apidemo\
'锘缟d' is not recognized as an internal or external command, operable program
or batch file.

[Solution]

If there are other matches in start.bat, type the command again in Notepad, or switch the encoding.

【Result after solution】

D:\apidemo>cd D:\apidemo\

The above is the detailed content of How to use bat to start springboot project. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete