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.