问题
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?
回答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).
回答2:
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.
回答3:
It is resolved after specifying absolute path
来源:https://stackoverflow.com/questions/19449546/crontab-ubuntu-java-not-working