I want to start gui-java application on startup. So I tried to use


with my .desktop

debian@debian:~$ cat /etc/xdg/autostart/alclient.desktop
[Desktop Entry]

and cat of client.sh:

if [ -f client.l4j.ini ] ; then
    OPTIONS=$(grep -v '^#' client.l4j.ini | tr -d "\r" | tr "\n" " ")
java $OPTIONS -jar client.jar

But when I restart my computer the application does not start.

I determnate two problems:

  1. When I try to start app from ~/

    debian@debian:~$ sh /home/debian/my/app/2.4.93/client/bin/client.sh
    Error: Unable to access jarfile client.jar

    But when I start from its own directory then all is ok.

    debian@debian:~/my/app/2.4.93/client/bin$ sh /home/debian/my/app/2.4.93/client/bin/client.sh
    Dec 20, 2015 9:25:12 PM checkJVMVersion
    WARNING: Run only with jre 1.8
  2. My app set some default directory for its own.

    Home Directory          = /home/debian/my/app/2.4.93/client
    Data Directory          = /home/debian/my/app/2.4.93/client/data
    Logs Directory          = /home/debian/my/app/2.4.93/client/logs
    Config Directory        = /home/debian/my/app/2.4.93/client/conf
    Locale Directory        = /home/debian/my/app/2.4.93/client/locale

I'm afraid that app will use other directory rather than define if start from /etc/xdg/autostart/

How I should correct setup autostart after login?

1 Answer 1


Keeping your existing setup as described in your question, modify client.sh like so:



this_dir="$(dirname "$(realpath "$0")")"

if [ -f "$this_dir/client.l4j.ini" ] ; then
    OPTIONS=$(grep -v '^#' "$this_dir/client.l4j.ini" | tr -d "\r" | tr "\n" " ")

java $OPTIONS -jar "$this_dir/client.jar"

Save, then, restart your computer, see if it now starts up.


  • /etc/xdg/autostart desktop file looks fine, so more likely the script it runs, client.sh, is the source of the problem
  • the script client.sh that you posted had an extra backslash: \#!/bin/sh, but normally it is just #!/bin/bash to specify bash, or in your case #!/bin/sh is fine and let your system decides what sh should run, bash or otherwise.
  • you said client.sh fails to work when run elsewhere but works when called from same directory containing client.sh, plus I see client.sh makes references to file names directly with no other code clarifying paths, which all suggests path problems
  • referencing file names directly like that works only when current working directory contains those files, so to deal with uses when you are not running client.sh in the containing directory, we need to add extra code to help the script determine the full path
  • this_dir="$(dirname "$(realpath "$0")")" is based on Bash - refer to a file under the same directory where $0 is the full path to client.sh, realpath resolves in case there are sym link issues, and dirname just then obtains the path except for client.sh, thus obtaining the containing directory, saving it $this_dir
  • $this_dir/client.l4j.ini: containing directory +file, so script can properly find client.l4j.ini
  • $this_dir/client.jar: containing directory +file, so script can properly find client.jar

So, now that the script can properly find all the files necessary to run, and as long as you you restart to make it effective, it should now run.

  • ** in **#!/bin/sh just typo. Thanks for reply I'll try it. There is another way to resolve my problem - property Path for my .desktop docs
    – Asker N
    Commented Dec 21, 2015 at 7:59
  • Nice find! Hope that works for you, it would be a much quicker fix than my answer.
    – clarity123
    Commented Dec 22, 2015 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .