3

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
  • 335
  • 3
  • 13
  • In your [other post](https://stackoverflow.com/questions/56916159), your screenshot *CUT OFF THE SINGLE MOST IMPORTANT PIECE OF INFORMATiON*. The error message: `Exec format error`. This is a systemd error. Look here: https://unix.stackexchange.com/questions/303022/systemd-exec-format-error and here: https://superuser.com/questions/944244/running-a-java-process-from-systemd – paulsm4 Jul 07 '19 at 06:24
  • @paulsm4 Thank YOu for the information. Yes I know this is a systemd error. But how to resolve it is the problem. The posts you mentioned are informative but does not solve the problem for me yet. – Mandeep Jul 07 '19 at 19:58
  • @paulsm4 any suggestion would be appreciated if you need the jar file i ll post it to you. – Mandeep Jul 07 '19 at 20:07
  • 1
    Thank you, but I don't need the .jar file. SUGGESTIONS: 1) Please read this additional link: https://stackoverflow.com/questions/21503883/, 2) modify your script to start with `#!/bin/bash`, include the fully qualified path to Java, and echo $PATH, $JAVA_HOME and $CLASSPATH. Copy/paste the output into your original post. 3) If you still can't figure it out, then write a JavaFX [MCVE] that reproduces the problem and copy/paste it into your original post. – paulsm4 Jul 07 '19 at 20:21
  • @paulsm4 I tried running a simple java jar and its working as expected and when i go back to same GUI1.jar it produces error. This time error may look different because i am not running script i am running jar file directly from service. This may help to understand issue. Please see the update. Thank You!!! – Mandeep Jul 07 '19 at 21:18
  • 1
    OK: that's useful information. So the problem is *NOT* with the script, and the problem is *NOT* with the difference between running your script from command line vs. from systemd environments. Q: So what exactly is the difference between the .jar that "works", and the one that doesn't? Q: You aren't trying to run GUI code as a service, are you? If so: Q1: Why? Q2: How do you expect that to work? SUGGESTION: I still recommend an [mcve]. – paulsm4 Jul 08 '19 at 04:15
  • @paulsm4 i figured the problem was with graphics and user level. Somehow the terminal should know to use graphic etc and ther terminal should have right user for calling it. I have added solution below and it works as expetced. But dont know the real reason i.e. working of these codes so if you know please post it. Thank You !!! – Mandeep Jul 08 '19 at 20:24

1 Answers1

2

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"

Mandeep
  • 335
  • 3
  • 13