Re : Pass parameters from Cron job to Java code

Hello All,

Hope all is fine. I am newbie to Unix. I am using Bourne Shell (sh). One of the question I have is that I am trying to read XML file and based on reading that XML file I want to run same java programs at different hours. When I run the Java code, I wanted to pass parameters to my compiled java code, for example : if I read 4 Apps (App1, App2, App3,App4) from XML and if I read different time to run the same java code for above mentioned parameters (App1,....).then I will have to set cron job at different time but my question is how will I pass parameters from cron job to java code at while running it.

This is what I want to do..............

05 14 * * * java ./program1(App1)
10 14 * * * java ./program1(App2)
15 14 * * * java ./program1(App3)
20 14 * * * java ./program1(App4)

Thanks in advance and appreciate your feedback on this.

Thanking you ,
Sam

Passing parameters to Java is usually done either through the environment. So, set an environment variable, like:

FOO="Parm1;parm2;parm3" java ./program1
FOO="Parm1;parm2;parm3" java ./program2

I might be wrong on a few details. For instance, maybe you need to pass the variables in with an option like java -d. Here's a link that will help you both on the unix side and in the java side: Read environment variables from an application - Real's Java How-to