0

I have a java program that works correctly when I run java -jar "lizzie.jar" from the terminal, but when I double click it in Nautilus it runs (i.e. UI shows) but returns the error "No such file or directory" for one of the files (./leelaz) it depends on to work properly.

I have created a .desktop file in /home/username/.local/share/applications with the following contents:

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Lizzie
Type=Application
Exec=java -jar "/home/username/opt/Lizzie/lizzie.jar"
Icon=/home/username/opt/Lizzie/lizzie_custom_logo.png
Comment=Lizzie
Terminal=false

Running this yields the same error as double-clicking.

I found and read this post, and I've tried using both Terminal=true and Terminal=false. The file lizzie.jar is set to allow executing as program and both when running from Nautilus and terminal I am not root. This might of course be an issue for Lizzie and not Ubuntu, but I think I should be able to generate the same behavior as if run from terminal.

Dist: Ubuntu 18.04.6 LTS; Kernel: 5.4.0-99-generic

java -version returns:

openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)

Question: What is the likely reason the behavior from double-clicking and running the .desktop is different from terminal, and how may I configure a .desktop file that gives exactly the same behavior as if I ran java -jar lizzie.jar from the terminal?

N.B. The program runs in both cases, but it can't access the dependency ./leelaz in the case of double-clicking or using .desktop. Lizzie then reports: Cannot run program "./leelaz": error=2, No such file or directory. But, the file ./leelaz is there, and again, everything works when run from terminal.

(In case of interest, the application is Lizzie, an interface for the Go AI Leela Zero.)

Christopher.L
  • 213
  • 1
  • 3
  • 12

1 Answers1

2

What is the likely reason the behavior from double-clicking and running the .desktop is different from terminal

When successfully running java -jar "lizzie.jar", your current working directory is the same as the directory where the file lizzie.jar resides. Otherwise, lizzie.jar would not be found.

lizzie.jar apparently expects to find files it needs in its own directory. You therefore need to make sure to set the current directory to that where "lizzie.jar" resides.

how may I configure a .desktop file that gives exactly the same behavior as if I ran java -jar lizzie.jar from the terminal?

Add the following desktop entry to the .desktop launcher:

Path=/home/username/opt/Lizzie/
vanadium
  • 88,010
  • This solved my problem! I am a bit curious as to why double-clicking the .jar file gave the same behavior though; wouldn't the working directory just be set to the directory of the file I am double clicking? – Christopher.L Feb 18 '22 at 15:04
  • Launching a file by double clicking launches it in the directory where it resides. – vanadium Feb 18 '22 at 15:25
  • Exactly, and this is /home/username/opt/Lizzie/ , i.e. the same as the path I set in .desktop which made the desktop-launcher work. – Christopher.L Feb 18 '22 at 15:28