Write a simple cron task to run a java class

How can I write the start of a cron job from stratch to run a java class, or write a cron job class with built-in java code to run?

and how can I set the timer to run every minute (for example), what is the cron job?

Note: fully beginner with linux

+4
source share
2 answers

Here is an example sh file that runs a test task

#!/bin/bash export JAVA_HOME=/usr/java/jdk1.6.0_07 echo "Java Home is $JAVA_HOME" export CLASSPATH=.:..:$CLASSPATH: echo "Path is is $PATH" echo "CLASSPATH is is $CLASSPATH" $JAVA_HOME/bin/java TestJob echo "$JAVA_HOME/bin/java TestJob" 

then point to it from your cronjob like this:

 0 5 * * * . $HOME/.profile; /path/to/command/test/job 
+4
source

If you are thinking of a simple cron task, you can use TimerTask

Quartz is also known for cron jobs in Java.

+1
source

All Articles