Jar后台运行脚本 window-bat/unix-sh for springboot

springboot项目,直接打包成jar

自带tomcat,可以通过java命令直接运行,无需web应用服务.

以maven为例,在pom.xml中配置打包输出类型:

<packaging>jar</packaging>

配置build:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

打包成jar后,可以通过批处理直接启动或者停止.

window-bat

start:

@echo off
:wmic process where "commandline like '%%-jar reportcheck%%'" call terminate
set path=C:\Program Files\Java\jre1.8.0_91\bin
START "reportcheck" "%path%\javaw" -jar reportcheck-0.0.1-SNAPSHOT.jar
pause

stop:

@echo off
wmic process where "commandline like '%%-jar reportcheck%%'" call terminate
pause

unix-sh

start:

#!/bin/bash
if ps aux | grep -v 'grep' | grep 'java' | grep 'reportcheck.jar'
then
pid=$(ps aux | grep -v 'grep' |grep 'java'|grep 'reportcheck.jar'| awk '{print $2}');
echo pid;
kill -9 ${pid};
echo old reportcheck exit...;
fi
nohup java -jar reportcheck.jar &> out &
echo reportcheck running...

stop:

#!/bin/bash
if ps aux | grep -v 'grep' | grep 'java' | grep 'reportcheck.jar'
then
pid=$(ps aux | grep -v 'grep' |grep 'java'|grep 'reportcheck.jar'| awk '{print $2}');
echo pid
kill -9 ${pid};
fi
posted @   一路漂泊  阅读(2332)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
点击右上角即可分享
微信分享提示