java cron job,Java程序的Cron作业

I am using a java program which sends email after finishing up some file transfers.I am using Eclipse to code up the program. How do I set up a cron job to execute this java program for a particular time. Also I have various jar files inside the project. Please suggest

解决方案

r0ast3d has a quick, clear answer - I did have to do some more searching to get each step done so I'll elaborate on his steps:

Write a shell script to invoke your java program with the necessary arguments.

Example:

!/bin/bash

echo "Running script."

cd ~/your/classpath/to/java

java -classpath .:somejar.jar path/to/your/Program

Separate your necessary classpaths with colons (:) rather than semicolons (;)

The path to your program should start with your package (find this at the top of the java program)

Make sure that the classpath argument points to the jars that you need.

You can check your import statements in your java program to make sure you are specifying all the necessary classpaths. You have to run this script from your java directory, and can use a single period (.) as your first classpath argument.

Make sure that the shell script has necessary unix permissions.

Run from a terminal: sudo chmod ### yourScript.sh

Where ### are numbers representing the correct permissions for your system setup.

Schedule the script to be invoked by setting up a cron job.

Run from a terminal: crontab -e

This will open your crontab editor. You can add a job in this way:

*/5 * * * * bash /home/scripts/yourScript.sh

Replace the path to the script with the correct location of your script. This job is set to run every 5 minutes. See http://www.adminschoice.com/crontab-quick-reference/ for a good reference on crontab.

Hope this helps someone out!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值