0

I have written a java program to launch various programs in linux with an attached API. I want this java program to run in the background as my user and start automatically on system boot. I have tried running the jar file from a systemd service but when trying to launch GUI applications it fails.

I understand that in order to run a GUI application two environment variables needs to be set: DISPLAY and XAUTHORITY

I've tried setting them in the systemd service file but the java process still fails to launch any GUI program. There is no problem launching GUI applications when running the jar file from a terminal.

Can this problem be solved with systemd or any other background daemon?

This is what my service file looks like:

[Unit]
Description=Application API
After=network.target

[Service]
User=me
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/me/.Xauthority
ExecStart=/usr/bin/java -jar /usr/local/bin/windows-application-launcher.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Update: It only needs to run when I'm logged in to my desktop environment.

5
  • Do you otherwise have a regular graphical desktop on this system? Does it use auto-login? Jul 1, 2017 at 19:17
  • It is a regular graphical desktop system but I do not use auto-login. However, it would never have to launch an application if my user is not logged in and the desktop environment is running.
    – Jimmy
    Jul 1, 2017 at 19:19
  • So why don't you start it as part of some login process? Just add a .desktop file for it in /etc/xdg/autostart (full spec here).
    – xenoid
    Jul 1, 2017 at 22:35
  • @xenoid That worked perfectly, thanks! I do not know why I did not think of that myself. Consider posting it as an answer to make it easier for others to find.
    – Jimmy
    Jul 2, 2017 at 8:51
  • @Jimmy Added (with a bit more detail)
    – xenoid
    Jul 2, 2017 at 9:59

1 Answer 1

1

Start your process as part of the login flow.

  • To add it for all users: add a .desktop file for it in /etc/xdg/autostart (full spec here).
  • To add it just for yourself, add the .desktop in ~/.config/autostart/. Your desktop manager likely has some settings dialog to do this for you -in KDE5 (System Settings): Settings>Workspace>Startup and shutdown>Autostart
2
  • I tried what you said above but I am getting statemnt as "No protocol specified". I am also stuck with the same scenario of Jimmy
    – user744875
    Jul 3, 2017 at 11:51
  • Please be more explicit, I suggested three things: 1) global, 2) personal via file and 3) personal via settings app. 3) is obviously easier. You also can use any application menu editor to create (and test) some .desktop (they are just "shortcuts"), and once it works you just move it to the adequate directory. Otherwise post .desktop used.
    – xenoid
    Jul 3, 2017 at 13:51

You must log in to answer this question.

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