Crontab + ubuntu + java not working

半世苍凉 提交于 2019-12-24 02:40:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!