crontab定时任务执行java 程序需要在crontab上有Java环境
一般使用一个shell 脚本来执行Java程序, 由定时任务去调度shell脚本
vim springboot-report-crontab.sh
#!/bin/sh
source /etc/profile
cd /usr/local/
cd /root/work/report/
java -jar -Dspring.config.location=/root/work/report/application-prod.properties springboot-report.jar
springboot加载外部配置文件文件
java -jar demo-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
-Dspring.config.location=classpath:
-Dspring.config.location=file:
如果有必要还需要在shell脚本 进行环境配置export 如CLASSPATH ,PATH
内部尽可能使用全路径
40 10 2 * * sh /root/work/report/springboot-report-crontab.sh>>/log/monitor/springboot-report.log 2>&1
#表示每个月的2号10点40发送邮件