1

java -jar /home/scripts/relay.jar is working fine when I launch from command line. The command produces a file: relay.txt

In crontab

/usr/bin/java -jar /home/oneprovider/relay.jar

is not producing anything. I first had it without /usr/bin/ but then did which java and added absolute path with no luck. The jar file was originally written for windows but it works in Linux fine when launched from command line

What am I missing?

8
  • can you verify the java process is running when it's supposed to run? Commented Feb 16, 2017 at 23:36
  • 1
    The command you're executing in crontab is different to the command you execute manually? Why don't you put java -jar /home/scripts/relay.jar in your crontab? Commented Feb 16, 2017 at 23:38
  • 2
    Also, where do you expect the file to be created (and why), and what is the code creating that file? Commented Feb 16, 2017 at 23:42
  • @JBNizet when I launch it from command line it creates the file in the same directory where the jar file is. The code is embedded in jar. Commented Feb 16, 2017 at 23:43
  • 1
    Then neither you, nor we can explain much. The code matters. My guess is that the code actually creates a file in the current directory, and that the current directory of the cron job is not your the directory containing the jar file. To make a car analogy: if I take my car and go 80km to the west, I'll end up in Lyon, France. You doing the same thing from your home will not lead you to the same place. Commented Feb 16, 2017 at 23:57

1 Answer 1

1

Agreed that the working directory is likely the problem. Can you write a shell script that wraps the java invocation and sets the working directory? Something like:

#!/bin/sh -e
cd /home/oneprovider 
/usr/bin/java -jar /home/oneprovider/relay.jar

Then change the cron job to run the script instead. Remember to chmod it and make sure that the cron user can write to the directory if it isn't your personal crontab.

Sign up to request clarification or add additional context in comments.

1 Comment

or use /usr/bin/java "-Duser.dir=/home/oneprovider" -jar /home/oneprovider/relay.jar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.