Java Cron和史诗失败了

时间:2016-03-31 21:05:58

标签: java bash cron classpath crontab

我在14.04.1-Ubuntu上运行它

  

Linux matlabrun 3.19.0-56-generic#62~14.04.1-Ubuntu SMP Fri Mar 11   11:03:15 UTC 2016 x86_64 x86_64 x86_64 GNU / Linux

使用java版本:

  

java版" 1.7.0_80" Java(TM)SE运行时环境(构建   1.7.0_80-b15)Java HotSpot(TM)64位服务器VM(内置24.80-b11,混合模式)

所以我的cron中有两个元素 testrun delme.jar

PATH=/usr/bin/java:/usr/bin/javac:/usr/lib/jvm/java-7-oracle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v85/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v85/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v85/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/$
    XAPPLRESDIR=/usr/local/MATLAB/MATLAB_Runtime/v85/X11/app-defaults:/usr/local/MATLAB/MATLAB_Runtime/v90/X11/app-defaults
    # Edit this file to introduce tasks to be run by cron.
    #
    # Each task to run has to be defined through a single line
    # indicating with different fields when the task will be run
    # and what command to run for the task
    #
    # To define the time you can provide concrete values for
    # minute (m), hour (h), day of month (dom), month (mon),
    # and day of week (dow) or use '*' in these fields (for 'any').#
    # Notice that tasks will be started based on the cron's system
    # daemon's notion of time and timezones.
    #
    # Output of the crontab jobs (including errors) is sent through
    # email to the user the crontab file belongs to (unless redirected).
    #
    # For example, you can run a backup of all your user accounts
    # at 5 a.m every week with:
    # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
    #
    # For more information see the manual pages of crontab(5) and cron(8)
    #
    # m h  dom mon dow   command
    5,10,15,20,30,35,40,43,45,50,52,55,58 * * * 0,1,2,3,4,5,6 /home/meh/model/TestModelABC/testrun > /home/meh/model/TestModelABC/testrun.log
    5,10,13,15,17,18,20,25,30,33,35,36,40,43,45,50,52,55,58 * * * 0,1,2,3,4,5,6 java -jar /home/meh/model/TestModelABC/delme.jar > /home/meh/model/TestModelABC/del.log

testrun是一个bash脚本,它调用java代码:

#!/bin/sh
java -jar delme.jar

这不起作用。当我通过crontab中的java -jar delme.jar直接调用文件时,它也不起作用。

我知道cron正在运行它只是不执行java。

为此,我可以看到放入crontab的路径,并尝试将路径放入bash脚本中,如下所示:

PATH=/usr/bin/java:/usr/bin/javac:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v85/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v85/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v85/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:
XAPPLRESDIR=/usr/local/MATLAB/MATLAB_Runtime/v85/X11/app-defaults:/usr/local/MATLAB/MATLAB_Runtime/v90/X11/app-defaults
echo "Forecast Test"

我现在真的被困住了,因为我没有尝试。有任何想法吗?我的直觉告诉我这是一个PATH问题,但我不知道还有什么可以尝试。

2 个答案:

答案 0 :(得分:0)

  

当我通过java -jar直接调用文件时,它也不起作用   delme.jar

听起来你没有可执行的jar文件。

确保在jar清单中设置了Main-Class: classname,或者直接运行该类,在类路径中指定jar。

e.g。 java -cp delme.jar path.to.package.Main

另请参阅:How to make an executable jar file?

答案 1 :(得分:0)

事实证明,这是CRON从/ home / user调用的路径问题,因此-cp中使用的任何相对路径都不再有效。