GUI javafx app not opening via service in linux

Mandeep :

I have created a GUI Javafx app and exported it to a jar file. The GUI app is working fine. After creating this app i have moved it to linux system and it is working fine here. Now i want to run this GUI app in linux using services so that i can make this service run at start of linux system.

For that I have created a pointless.sh file which on run runs the jar file. It is working perfectly the code for this pointless.sh file are

java -jar GUI1.jar

on Runinng this script i.e. "./pointless" the GUI is shown on the screen. enter image description here

Problem starts when i try to make a service for it.

I made a service for it in /etc/systemd/system pointless.service

[Service]
ExecStart=/home/mandeep/Documents/pointless.sh

on running sudo systemctl start pointless.service nothing happens and the status shows following errors.

● pointless.service
   Loaded: loaded (/etc/systemd/system/pointless.service; static; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-07-06 13:44:00 EDT; 25min ago
  Process: 1449 ExecStart=/home/mandeep/Documents/pointless.sh (code=exited, status=203/EXEC)
 Main PID: 1449 (code=exited, status=203/EXEC)

Jul 06 13:44:00 debian systemd[1]: Started pointless.service.
Jul 06 13:44:00 debian systemd[1449]: pointless.service: Failed at step EXEC spawning /home/mandeep/Documents/pointless.sh: Exec format error
Jul 06 13:44:00 debian systemd[1]: pointless.service: Main process exited, code=exited, status=203/EXEC
Jul 06 13:44:00 debian systemd[1]: pointless.service: Unit entered failed state.
Jul 06 13:44:00 debian systemd[1]: pointless.service: Failed with result 'exit-code'.

Update !!!

Step 1 As expected I created a simple Java app helloworld and exported it to jar file. I ran this file as java -jar helloworld and It worked.

Step 2 I created a simple service for it and service also worked as expected. the service codes are

[Service]
ExecStart=/usr/bin/java -jar /home/mandeep/Documents/helloworld.jar

Output

Jul 07 17:08:13 debian systemd[1]: Started pointless.service.
Jul 07 17:08:13 debian java[2765]: Hello World!

Step 3 I Updated service back to GUI1.jar to check original problem posted. code

[Service]
ExecStart=/usr/bin/java -jar /home/mandeep/Documents/GUI1.jar

and again it shows the error

Output

● pointless.service
   Loaded: loaded (/etc/systemd/system/pointless.service; static; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2019-07-07 17:14:37 EDT; 4s ago
  Process: 2816 ExecStart=/usr/bin/java -jar /home/mandeep/Documents/GUI1.jar (code=exited, status=1/FAILURE)
 Main PID: 2816 (code=exited, status=1/FAILURE)

Jul 07 17:14:37 debian java[2816]:         at com.sun.glass.ui.Application.run(Application.java:146)
Jul 07 17:14:37 debian java[2816]:         at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
Jul 07 17:14:37 debian java[2816]:         at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
Jul 07 17:14:37 debian java[2816]:         at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
Jul 07 17:14:37 debian java[2816]:         at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:337)
Jul 07 17:14:37 debian java[2816]:         at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
Jul 07 17:14:37 debian java[2816]:         ... 5 more
Jul 07 17:14:37 debian systemd[1]: pointless.service: Main process exited, code=exited, status=1/FAILURE
Jul 07 17:14:37 debian systemd[1]: pointless.service: Unit entered failed state.
Jul 07 17:14:37 debian systemd[1]: pointless.service: Failed with result 'exit-code'.
Mandeep :

Found the answer

Made following changes under [Service] in pointless.service

a) use "Environment=DISPLAY:=0"

b) declare "User=<user>"

and under [Install] optional

c) declare "WantedBy=<user>@.service"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=155304&siteId=1