【jar包运行与终止】

文章描述了如何使用`java-jar`命令运行SpringBoot应用的jar包,通过`jps`查询进程ID(PID),然后使用`taskkill`命令终止进程。在尝试运行时遇到了PortInUseException,因为端口8099已被占用,提示用户需停止使用该端口的进程或更改应用监听的端口。

运行jar包

输入java -jar 要运行的jar包.jar

终止运行jar包

分两步:
①查询运行jar的PID,输入如下命令:

C:\Users\Administrator\IdeaProjects\springflutterdemo\target>jps
12916
13764 Jps
14680 RemoteMavenServer36
14748 springflutterdemo-0.0.1-SNAPSHOT.jar
14844 Launcher

②杀死进程

taskkill /pid 进程的PID编号 -f  -t

例子

C:\Users\Administrator\IdeaProjects\springflutterdemo\target>java -jar springflutterdemo-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::               (v2.6.11)

2023-03-16 08:25:41.577  INFO 13440 --- [           main] c.e.s.SpringflutterdemoApplication       : Starting SpringflutterdemoApplication v0.0.1-SNAPSHOT using Java 15 on JieLenovoPC with PID 13440 (C:\Users\Administrator\IdeaProjects\springflutterdemo\target\springflutterdemo-0.0.1-SNAPSHOT.jar started by Administrator in C:\Users\Administrator\IdeaProjects\springflutterdemo\target)
2023-03-16 08:25:41.593  INFO 13440 --- [           main] c.e.s.SpringflutterdemoApplication       : No active profile set, falling back to 1 default profile: "default"
2023-03-16 08:25:42.939  INFO 13440 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8099 (http)
2023-03-16 08:25:42.953  INFO 13440 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-03-16 08:25:42.954  INFO 13440 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.65]
2023-03-16 08:25:43.039  INFO 13440 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-03-16 08:25:43.040  INFO 13440 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1368 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Parsed mapper file: 'class path resource [mapper/UserMapper.xml]'
2023-03-16 08:25:43.768  WARN 13440 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.PortInUseException: Port 8099 is already in use
2023-03-16 08:25:43.773  INFO 13440 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-03-16 08:25:43.787  INFO 13440 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-03-16 08:25:43.810 ERROR 13440 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 8099 was already in use.

Action:

Identify and stop the process that's listening on port 8099 or configure this application to listen on another port.


C:\Users\Administrator\IdeaProjects\springflutterdemo\target>jps
12916
13764 Jps
14680 RemoteMavenServer36
14748 springflutterdemo-0.0.1-SNAPSHOT.jar
14844 Launcher

C:\Users\Administrator\IdeaProjects\springflutterdemo\target>taskkill /pid 14748 -f  -t
成功: 已终止 PID 14748 (属于 PID 12916 子进程)的进程。

C:\Users\Administrator\IdeaProjects\springflutterdemo\target>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值