gradle结合spring-boot生成可运行jar包,并打印日志

1.用gradle把springboot项目打包成jar

1.1 build.gradle 中添加

buildscript { 
    repositories {
        mavenLocal()
        maven { url "http://*.*.*.*:*/nexus/content/groups/public/" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

注意:apply plugin: 'war' //这一行不要加,否则很有可能打不了jar包,只能打出来war包

1.2 执行构建命令

 gradle bootRepackage

2.打印日志,利用shell启动并配置log日志

2.1 启动项目

#!/bin/bash
echo starting...
java -jar topca-storage-srv-1.0.0.jar > log.file 2>log.error &

2.2 停止正在运行的项目

#!/bin/bash
PID=$(ps -ef | grep topca-storage-srv-1.0.0.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill $PID
fi

2.3 重启项目

#!/bin/bash
echo stop application ...
source stop.sh
echo start application ...
source start.sh
posted @ 2019-04-09 14:13  小小小小小小鱼  阅读(1870)  评论(0编辑  收藏  举报