简体   繁体   English

Crontab + Ubuntu + Java不起作用

[英]Crontab + ubuntu + java not working

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. 但是,当我在ubuntu服务器中将其设置为crontab时,它将无法正常工作。

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

Any one know why unexpected behavior? 有人知道为什么会有意想不到的行为吗?

The crontab task is executed under a different user from the one with which you are testing the call. crontab任务是在与测试呼叫的用户不同的用户下执行的。 JBoss depends on a number of environment variables, which are probably undefined in that context. JBoss依赖于许多环境变量,在这种情况下可能未定义。 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). 因此,从环境中找出特定的JAR需要什么,然后将其添加到您从cron任务运行的shell脚本中(而不是直接从cron运行java )。

即使您正在读取或写入文件,即使jar文件和读取文件位于同一目录中,也请确保在源代码中包含绝对路径。

指定绝对路径后解析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM