Linux环境部署运行Jar包指定JDK版本创建启停服务脚本

window系统下部署测试后需要迁移到Linux系统下生产环境运行,由于生产环境设定JAVA_HOME的JDK版本还是1.6,需要指定1.8版本JDK运行Jar包,本文以指定JDK版本创建启停Jar服务的脚本。

创建应用启停空文件脚本并授权读写可执行权限

创建空文件命令:touch

[root@dbtest test]# touch webService-start.sh webService-stop.sh
[root@dbtest test]# ll
总计 16
-rw-r--r-- 1 root root    0 11-20 10:55 webService-start.sh
-rw-r--r-- 1 root root    0 11-20 10:55 webService-stop.sh
[root@dbtest test]#

授读写可执行权限命令:chmod

[root@dbtest test]# chmod 755 webService-start.sh webService-stop.sh
[root@dbtest test]# ll
总计 16
-rwxr-xr-x 1 root root    0 11-20 10:55 webService-start.sh
-rwxr-xr-x 1 root root    0 11-20 10:55 webService-stop.sh
[root@dbtest test]#

查看当前JDK安装路径:echo $JAVA_HOME

[root@dbtest test]# echo $JAVA_HOME
/root/jrockit-jdk1.6.0_29-R28.2.2-4.1.0
[root@dbtest test]#

由于开发的Jar是运行在JDK1.8环境中,所以直接使用java命令运行Jar包是会报错的,就需要安装1.8的JDK,并指定JDK运行Jar。

编辑启动服务脚本

[root@dbtest test]# vi webService-start.sh
JAVA_HOME=/usr/lib/jdk1.8.0_191
#日志文件目录
LOG_HOME=/root/Oracle/Project/logs
#可运行Jar文件部署目录
JAR_HOME=/root/Oracle/Project/jar

cd $JAVA_HOME
$JAVA_HOME/bin/java -jar $JAR_HOME/web-service-0.0.1-SNAPSHOT.jar >$LOG_HOME/nohup.out&
cd $LOG_HOME
#启动脚本输出启动日志信息
tail -f nohup.out
~
~
~
~
~
~
~
"webService-start.sh" 11L, 296C written
[root@dbtest test]#

编辑停止服务脚本

[root@dbtest test]# vi webService-stop.sh
#! /bin/sh
#可运行Jar文件部署目录
JAR_HOME=/root/Oracle/Project/jar
#获取运行Jar进程ID号
pid=`ps -ef |grep $JAR_HOME/web-service-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{print $2}'`
#kill进程 
kill -9 $pid

echo "The service has stopped !"
~
~
~
~
~
"webService-stop.sh" 9L, 241C written
[root@dbtest test]#

运行启动服务命令

[root@dbtest test]#./webService-start.sh
09:47:23 -0    [main] DEBUG   - Adding [systemProperties] PropertySource with lowest search precedence
09:47:23 -12   [main] DEBUG   - Adding [systemEnvironment] PropertySource with lowest search precedence
09:47:23 -13   [main] DEBUG   - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
09:47:23 -18   [main] INFO    - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4f2410ac: startup date [We
d Nov 20 09:47:23 CST 2019]; root of context hierarchy
09:47:23 -75   [main] DEBUG   - Adding [systemProperties] PropertySource with lowest search precedence
09:47:23 -76   [main] DEBUG   - Adding [systemEnvironment] PropertySource with lowest search precedence
09:47:23 -76   [main] DEBUG   - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
09:47:23 -90   [main] INFO    - Loading XML bean definitions from class path resource [spring-mybatis.xml]
09:47:24 -118  [main] DEBUG   - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
09:47:24 -170  [main] DEBUG   - Loading schema mappings from [META-INF/spring.schemas]

............

运行停止服务命令

[root@dbtest test]#./webService-stop.sh
The service has stopped !
[root@dbtest test]#

Maven项目打包pom.xml配置

请参考博客:https://blog.csdn.net/weixin_39699061/article/details/103074630

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值