Visit Our UNIX and Linux User Community

Running java class with a cron

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running java class with a cron
# 1  
Old 10-25-2005
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. Smilie

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
# 2  
Old 10-25-2005
You might try printing the $CLASSPATH shell variable in your shell script to see if all is OK.
# 3  
Old 10-26-2005

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

This User Gave Thanks to sanjustudy For This Post:
# 4  
Old 10-27-2005
In CronJava.txt do this:

echo $CLASSPATH > /tmp/cronout

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


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.

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Simplify setter and getter of java class

I am trying to verify my understanding on setter and getter on java class with this example: // import java.util.Scanner; public class MaximumFinder2 { public static void main (String args) { Scanner input = new Scanner(; ... (6 Replies)
Discussion started by: yifangt
6 Replies

2. Programming

Java Date Class

I am looking at a website to learn Java and this is one of the exercises. Write a program that will show different time and date information based on what number you send it. The codes are: 0 - number of milliseconds since January 1, 1970 1 - number of seconds since January 1, 1970 2 -... (6 Replies)
Discussion started by: totoro125
6 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. Programming

Link array to class java

Hi, I need help to Link array from one class to another class Firstly CSVParser Class what it did is load csv file and store into array Secondly WarehouseItem where each record is store How can I get a list of array that I load to CSVParser Class and store them to WarehouseItem and... (0 Replies)
Discussion started by: guidely
0 Replies

5. Programming

Help in JAVA main and class

Is anyone know how to write a class in separate file? While method does it needs to be contained in a printwriter class? Can I have the format of the printwriter class as a reference? Thanks a lot. (1 Reply)
Discussion started by: eel
1 Replies

6. Programming

how abstract class differs in Java and C++?

hello all, i want to know if there is any difference in working and syntax declaration of abstract class in Java and C++. (1 Reply)
Discussion started by: haravivar
1 Replies

7. Fedora

Help, how to dynamicly load java class

Hi, everyone: I'm trying to connect to DB using JDBC on fedora. I have successfully installed jdk and it's ok to run common java program. The environment variables: JAVA_HOME=/installed/mycoy/jdk1.6.0 PATH=$JAVA_HOME/bin:$PATH... (3 Replies)
Discussion started by: mycoy
3 Replies

8. Shell Programming and Scripting

call constructor of java class in script

Hi, Is it possible to call the constructur of a java class in a shell script? I know you can call static methods, but can you also call the constructor? tnx. (1 Reply)
Discussion started by: thebladerunner
1 Replies

9. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies

Featured Tech Videos