2

So I created a script the the following commands

#! /usr/bin/sh

    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    JAVA=/usr/bin/java
    MY_SERVER=/home/user/Desktop/Hello.jar
    USER=user
    /bin/su - $USER -c "$JAVA -jar $MY_SERVER &"

And I saved it in

etc/init.d/

And then ran the following command in terminal

sudo update-rc.d java_server_launch.sh defaults

I have a program located at

/home/user/Desktop/

And it is called Hello.jar and it works fine when I run it. When I restart my computer for some reason the program (Hello.jar) does not execute. What am I doing wrong?

I'm doing exactly what the answer here says.

Community
  • 1
  • 1
user2612619
  • 1,119
  • 3
  • 11
  • 28

2 Answers2

2

You need to replace Hello.jar with $MY_SERVER in the last line of your bash script. That's because your current working directory isn't /home/user/Desktop

Edit: Try replacing the last line of code with this:

/bin/su $USER -c "$JAVA -jar $MY_SERVER &"
MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
0

if you're running on Ubuntu you should check out upstart

see how simple it is to run jar https://stackoverflow.com/a/12102542/41576

Community
  • 1
  • 1
Guy Gavriely
  • 11,228
  • 6
  • 27
  • 42
  • I'd rather have a solution that doesn't involve installing other programs and one that will work on other Linux distributions as I don't only use Ubuntu. – user2612619 Dec 08 '13 at 00:43