File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to call a cron job from JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to call a cron job from JAVA" Watch "How to call a cron job from JAVA" New topic

How to call a cron job from JAVA

Dhondiba Joshi
Ranch Hand

Joined: Jan 23, 2004
Posts: 39
How to call a cron job from JAVA ?

any kind of help appreciated.

Dhondiba Joshi
Ranch Hand

Joined: Jan 23, 2004
Posts: 39
Hi all,

I meant how to run a java program from a cron job.Anybody ?

Nandakumar Subramaniam

Joined: Aug 11, 2004
Posts: 4
Write a batch file or shell script executing the java class. Schedule the script in ur cron tab.

Sample of an entry in the crontab.
# script to run the dashboard job
5,15,25,35,45,55 * * * * /usr/local/app/nps/scripts/

Sample of a shell script is given below:

#! /bin/bash

function alive() {
ps -eaf | grep -v grep | grep -c

if [ `alive` == 1 ]
pid_var=`ps -ef | grep com.test.job.RunJob | grep -v grep | awk '{print $2}'`
kill -9 $pid_var

if [ `alive` == 0 ]
export LIBDIR=/usr/lpp/CommerceSuite/lib
export CLASSPATH=/usr/local/appupdates/digester:$LIBDIR/axis.jar:$LIBDIR/commons-logging.jar:$LIBDIR/jaxrpc.jar:$LIBDIR/commons-digester.jar:$LIBDIR/siemens.jar:$LIBDIR/AppInterfaceDevTools.jar:$LIBDIR/jconn2.jar:$LIBDIR/xerces.jar:$LIBDIR/xml4j.jar:$LIBDIR/activation.jar:$LIBDIR/mail.jar:$LIBDIR/NetComponents.jar:$LIBDIR/commons-collections.jar:$LIBDIR/commons-dbcp.jar:$LIBDIR/commons-pool.jar:$LIBDIR/log4j.jar:$LIBDIR/freetds_jdbc.snapshot.jar:/usr/local/lib/jar/$LIBDIR/jms.jar:$LIBDIR/im q.jar:$LIBDIR/fscontext.jar:$LIBDIR/ibmjcefw.jar:$LIBDIR/ibmjceprovider.jar:$LIBDIR/wcsruntime.jar:$LIBDIR/commons-discovery.jar:$LIBDIR/saaj.jar:$LIBDIR/commons-beanutils.jar:$CLASSPATH
export PATH=/usr/java14/bin:$PATH
export JAVA_HOME=/usr/java14/
java com.test.job.populator.RunJob

Hope this helps.
I agree. Here's the link:
subject: How to call a cron job from JAVA
It's not a secret anymore!