GUI JavaFX应用程序无法通过Linux中的服务打开

时间:2019-07-06 18:18:48

标签: java linux javafx raspberry-pi debian

我创建了一个GUI Javafx应用程序并将其导出到jar文件。 GUI应用程序运行正常。创建此应用程序后,我已将其移至linux系统,并且在这里工作正常。现在,我想使用服务在Linux中运行此GUI应用程序,以便可以在Linux系统启动时运行此服务。

为此,我创建了一个pointless.sh文件,该文件在运行时运行jar文件。

,此pointless.sh文件的代码运行得很好。
java -jar GUI1.jar

在运行该脚本时,即“ ./pointless”GUI会显示在屏幕上。 enter image description here

当我尝试为其提供服务时,问题开始了。

我在/ etc / systemd / system pointless.service中为其提供了服务

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

在运行sudo systemctl start pointless.service时没有任何反应,并且状态显示以下错误。

● 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'.

更新!!!

第1步 如预期的那样,我创建了一个简单的Java应用程序helloworld,并将其导出到jar文件。我以java -jar helloworld的身份运行了该文件,并且有效。

第2步 我为此创建了一个简单的服务,该服务也按预期工作。 服务代码是

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

输出

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

第3步 我将服务更新回GUI1.jar以检查发布的原始问题。 代码

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

再次显示错误

输出

● 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'.

1 个答案:

答案 0 :(得分:1)

找到答案

在pointless.service的[Service]下进行了以下更改

a)使用“ 'direct adapation of Mathieu's function Public Function ContainsAny(ByVal data As String, ByVal caseSensitive As Boolean, ParamArray searchterms() As Variant) As Boolean Dim k As Integer Dim found As Boolean For k = LBound(searchterms) To UBound(searchterms) found = Contains(data, CStr(searchterms(k)), caseSensitive) If found Then Exit For Next ContainsAny = found End Function Public Function Contains(ByVal data As String, ByVal searchterms As String, Optional ByVal caseSensitive As Boolean = False) As Boolean Dim compareMethod As VbCompareMethod If caseSensitive Then compareMethod = vbBinaryCompare Else compareMethod = vbTextCompare End If Contains = (InStr(1, data, searchterms, compareMethod) <> 0) End Function 'attempt at replicating the function to return true when none of the strings are found Public Function DoesNotContainAny(ByVal data As String, ByVal caseSensitive As Boolean, ParamArray searchterms2() As Variant) As Boolean Dim n As Integer Dim notfound As Boolean For n = LBound(searchterms2) To UBound(searchterms2) notfound = DoesNotContain(data, CStr(searchterms2(n)), caseSensitive) If notfound Then Exit For Next DoesNotContainAny = notfound End Function Public Function DoesNotContain(ByVal data As String, ByVal searchterms2 As String, Optional ByVal caseSensitive As Boolean = False) As Boolean Dim compareMethod As VbCompareMethod If caseSensitive Then compareMethod = vbBinaryCompare Else compareMethod = vbTextCompare End If DoesNotContain = (InStr(1, data, searchterms2, compareMethod) = 0) End Function 'applied within various If/Then/ElseIfs like this: For i = 2 To LastRow 'For each row, return True if Columns F&G don't match AND that Col G contains H54 AND that Col F does NOT contain H54 If PCPJ.Range("F" & i) <> PCPJ.Range("G" & i) And _ (ContainsAny(PCPJ.Range("G" & i), False, "H54") And DoesNotContainAny(PCPJ.Range("F" & i), False, "H54")) Then 'Check for duplicate UniqueID in CoderBook Referrals sheet to avoid copying duplicate rows DuplicateCheck = Application.Match(PCPJ.Range("R" & i).Value, Referral.Columns(18), 0) If IsError(DuplicateCheck) Then 'If no matches are found on UniqueID, then copy appropriate rows to CoderBook Referrals sheet Referral.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).EntireRow.Value = PCPJ.Rows(i).Value End If 'For each row, return True if Columns F&G don't match AND that Col G contains B17 or B18 AND that Col F does NOT contain B17 or B18 ElseIf PCPJ.Range("F" & i) <> PCPJ.Range("G" & i) And _ (ContainsAny(PCPJ.Range("G" & i), False, "B17", "B18") And _ DoesNotContainAny(PCPJ.Range("F" & i), False, "B17", "B18")) Then DuplicateCheck = Application.Match(PCPJ.Range("R" & i).Value, Referrals.Columns(18), 0) If IsError(DuplicateCheck) Then Referrals.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).EntireRow.Value = PCPJ.Rows(i).Value End If 'Etc...

b)声明“ Environment=DISPLAY:=0

并在[安装]可选下

c)声明“ User=<user>