Java Cron job to run a jar file

摘要: Quartz is good, but often times we just need a simple scheduler system to run a jar file periodically. On *unix system, you can use the build-in cron to schedule a scheduler job easily.

Quartz is good, but often times we just need a simple scheduler system to run a jar file periodically. On *unix system, you can use the build-in cron to schedule a scheduler job easily.

In this example, we will show you how to create a cron job on *nix to run a jar file, by daily and hourly.

1. Create a Cron Job

To create a cron job, in terminal, type crontab -e to edit the cron job. Review following examples :

1.1 Run daily at 00:00, accepts two parameters.

# run everyday
0 0 * * * java -jar /home/mkyong/crawler/webcrawler.jar param1 param2

1.2 Run daily at 02:00 am, pass rir.name as a system property with -D option.

# run everyday at 2am
0 2 * * * java -jar -Drir.name="ripe" /home/mkyong/crawler/whoiscrawler.jar

1.3 Run hourly, assume this jar is logging message with the logback framework.

# run every hour
0 * * * * java -jar -Dlogback.configurationFile=/home/mkyong/logback.xml /home/mkyong/crawler/crawler.jar

Exit, save and override, done.

Display Cron Jobs
To display the existing cron job, type crontab -l

References

  1. Wikipedia – Cron
  2. Linux Crontab: 15 Awesome Cron Job Examples
  3. Crontab – Quick Reference

上一篇: Maven – Create a fat Jar file One-JAR example
下一篇: Java Read a text file line by line
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号