2

If I directly run the bellow code in terminal it is working perfect.

/usr/bin/java -jar /var/jboss-as-7.1.1.Final/standalone/email_linux/notification_18.jar

But when I set the same as a crontab in ubuntu server then it is not working.

*/3 * * * * /usr/bin/java -jar /var/jboss-as-7.1.1.Final/standalone/email_linux/notification_18.jar

Any one know why unexpected behavior?

vishal
  • 685
  • 2
  • 6
  • 9

3 Answers3

1

The crontab task is executed under a different user from the one with which you are testing the call. JBoss depends on a number of environment variables, which are probably undefined in that context. So find out what that particular JAR needs from the environment and then add it into a shell script which you run from the cron task (instead of directly running java from cron).

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • I have created following into sh file /usr/bin/java -jar /var/jboss-as-7.1.1.Final/standalone/email_linux/notification_18.jar now added following code in crontab */3 * * * * sh /var/jboss-as-7.1.1.Final/standalone/email_linux/startup.sh But some how it is not working. How to know that list of environment variable to setup path – vishal Oct 18 '13 at 13:07
  • Start with the variables which are defined in your shell, where everything works, and look for anything JBoss-specific and/or Java-specific. – Marko Topolnik Oct 18 '13 at 13:18
0

Make sure that you have included the absolute paths in the source code if you are reading or writing to a file, even if the jar file and the reading file are in the same directory.

Arjan
  • 1
0

It is resolved after specifying absolute path

vishal
  • 685
  • 2
  • 6
  • 9