栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

jar包打成服务

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jar包打成服务

一、windows版

1.在idea中用maven将程序打成jar,放到目录中。
2.去github上面下载winsw: https://github.com/kohsuke/winsw/releases
3. 将WinSW.NET4.exe文件复制到java程序所在文件夹中
4.将java程序重命名,去掉名称中的“.”。例如hello-1.0.jar ----> hello.jar
5.将WinSW.exe重命名为hello.exe(和jar同名)
6. 新建一个xml文件,命名为hello.xml


     hello
     hello
     This is hello service.
     
     
     java
    -jar "E:springboothello.jar"
     
     Automatic
     
     E:springbootlog
     rotate
 

7.命令行定位到当前目录,执行: hello.exe install
8. 去windows服务列表中启动程序。

二、linux版

1、创建新文件 touch /etc/rc.d/init.d/hello
2、编辑文件 vi /etc/rc.d/init.d/hello
3、编辑内容

#!/bin/bash
#chkconfig: 2345 10 90
#description:hello
base_DIR="/root/hello"      #jar包存放的路径
JAR_FILE="hello.jar"		#jar包名称
SERVICE_NAME="helloAp9000"  #服务名称

start()  
{  
echo "starting ${SERVICE_NAME}..."
cd $base_DIR
nohup java -jar $JAR_FILE > /root/hello/hello.out 2>&1
echo "${SERVICE_NAME} started"
}  

stop()  
{  
echo "stopping ${SERVICE_NAME}..."  
pid=`ps -ef|grep $JAR_FILE |grep -v grep |awk '{print $2}'`
kill -9 $pid 
echo "${SERVICE_NAME} stopped"
}

case "$1" in

start)  
start 
;;

stop)  
stop 
;; 

restart)  
stop  
start  
;;

*) 
echo "Usage: `basename $0` start|stop|restart"
esac 
exit 0

4、赋予权限 chmod +x /etc/rc.d/init.d/hello
5、设置开机启动 chkconfig --add hello
6、启动服务 ./hello start
7、停止服务 ./hello stop

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/644697.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号