0

im running this on 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

using java version:

java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

So I have two elements in my cron testrun and 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 is a bash script that calls java code as so:

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

This doesn’t work. It also doesn't work when i call the file directly via the java -jar delme.jar from within crontab.

I know the cron is running its just not executing the java.

To that end i have as you can see put in the path's to the crontab as well as have tried to put the path into the bash script like so:

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"

I am really stuck now as im out of things to try. Any ideas? My gut is telling me it is a PATH issue but I don't know what’s left to try.

DevilCode
  • 1,054
  • 3
  • 35
  • 61

2 Answers2

0

It also doesn't work when i call the file directly via the java -jar delme.jar

It sounds like you don't have an executable jar file.

Make sure that you have Main-Class: classname set in the jar manifest, or run the class directly, specifying your jar on the classpath.

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

See also: How to make an executable jar file?

Community
  • 1
  • 1
starf
  • 1,063
  • 11
  • 15
  • I've been debugging `cron` all day. Every problem is a nail, eh. This is probably the issue. In Eclipse, you ought to use the Export function to build a runnable jar. – ifly6 Mar 31 '16 at 21:26
  • @ifly6 We've all been there, but let's wait until the OP confirms! – starf Mar 31 '16 at 21:29
  • Im pretty sure the jar is executable as it runs fine when I run java - jar delme.jar via the command line. It also runs fine if i run the ./testrun from the command line. The only time it doesn't work is when its run from crontab. Cron calls the bash script ok but when its called via cron it will not run the jar. I don't get anything in the testrun.log file. – DevilCode Apr 01 '16 at 01:52
  • It also doesn't work when i call the file directly via the java -jar delme.jar is only when called within CRON. It runs perfectly fine when called like so via command line. – DevilCode Apr 04 '16 at 11:31
0

It turns out that it is a path issue where the CRON is calling from /home/user and as such any relative paths which were used in the -cp no longer worked.

DevilCode
  • 1,054
  • 3
  • 35
  • 61