Running java class with a cron

Hello everybody,

I have a problem about running a java class with a cron :

I have Cron.txt file which has :
0,5,10,15,20,25,30,35,40,45,50,55 * * * * CronJava.txt

I have CronJava.txt wihich has :
cd ias/j2ee/SapAktarim/applications/SapAktarim/SapAktarim/WEB-INF/classes/;java -classpath $CLASSPATH main.SapAktarim

When cron works I get "help of java command" from my mail.

if i do it manually, cd to path and type
java -classpath $CLASSPATH main.SapAktarim it works without a problem.

When I place it in a cron, I get this situation. :frowning:

Maybe cron can't see my user classpath info.

When I try a sipmle class which only system.out.println("Hello") it works with the cron ...?

I am new on Unix...

Helps appreciated...

Thanks a lot

You might try printing the $CLASSPATH shell variable in your shell script to see if all is OK.

Hai,

    in ur java class ur specfying some thing to print on console but  may be there may be no console 

opened to print ur s.o.println from crontab u can't start application which have GUI interface if u really want to start up like then install screen.rpm and in the crontab before the script calling specify it as

25 * * * * root screen -d -m myclass.java

:slight_smile:

1 Like

In CronJava.txt do this:

echo $CLASSPATH > /tmp/cronout

Wait a while. While you're waiting, do this:

echo $CLASSPATH

Compare that to the contents of /tmp/cronout. Are they the same? If not, do this ONCE:

echo "#!/bin/sh" > /tmp/tmpfile
echo "CLASSPATH=$CLASSPATH" >> /tmp/tmpfile
echo "export CLASSPATH" >> /tmp/tmpfile
cd /to/directory/where/your/CronJava.txtfile/is
cat CronJava.txt >> /tmp/tmpfile
# If you get any errors during the above actions, STOP. Try to fix them. Retry commands. If everything looks ok, then,
cp /tmp/tmpfile CronJava.txt

You should be all set.