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.
Do you otherwise have a regular graphical desktop on this system? Does it use auto-login? – user1686 – 2017-07-01T19:17:33.533
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 – 2017-07-01T19:19:08.103
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 – 2017-07-01T22:35:53.400@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 – 2017-07-02T08:51:30.233
@Jimmy Added (with a bit more detail) – xenoid – 2017-07-02T09:59:09.207