Java App in Flatpak Can't Execute Command From .var/app/APP_ID/ Filesystem - "No such file or directory"
Jun 30, 2022
D
Dan G
#1
Hello everyone,
I’m trying to package an Open Runescape Classic launcher called OpenRSC. Unfortunately, I’m getting the following exception that doesn’t happen outside of Flatpak:
java.io.IOException: Cannot run program "java" (in directory "/home/wacket/.var/app/vet.rsc.OpenRSC.Launcher/extras/winrune/WinRune-master"): error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
at java.base/java.lang.Runtime.exec(Runtime.java:594)
at launcher.Utils.CmdRunner.run(CmdRunner.java:29)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
... 4 more
Looking at the source code, OpenRSC Launcher does the following steps:
Downloads the game client
Uses some CmdRunner (which takes a command and path to run the command on) to runjava -jar /home/wacket/.var/app/vet.rsc.OpenRSC.Launcher/extras/winrune/WinRune-master inside the /home/wacket/.var/app/vet.rsc.OpenRSC.Launcher/extras/winrune/ directory
Based on the stacktrace, it seems CmdRunner can’t enter the /home/wacket/.var/app/vet.rsc.OpenRSC.Launcher/extras/winrune/ directory (although the directory exists on my system; I can cd into it).
Does anyone have any ideas on what I can do to make this work? I’m new to using Flatpak as a dev so I could be overlooking something simple.
Some things I’ve tried -
Granting full filesystem access
Using subdirectories inside .var/app/APP_ID/, such as data or cache
Not using .var/app/APP_ID to store the client’s downloads, and using filesystem access to specific folders instead
As an aside, it seems to be able to download files into the directory and detect them no problem. It just can’t run java from inside the directory
I have a copy of the Flatpak on my Github here if anyone wants to see specifics
D
Dan G
#2
Reading the stack more closely, it says Cannot run program java… Perhaps it’s referring to not being able to find “java”, rather than not being able to find the directory.
messias@messias:~/Workspace/flathub$ flatpak-builder build-dir io.github.appoutlet.GameOutlet.yml --force-clean
Downloading sources
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/messias/Workspace/flathub/.flatpak-builder/git/https_github.com_AppOutlet_GameOutlet.git-X1ZU31/
Fetching git repo https://github.com/AppOutlet/GameOutlet.git, ref refs/heads/main
remote: Enumerating objects: 261, done.
remote: Counting objects: 100% (261/261), done.
remote: Compressing objects: 100% (227/227), done.
remote: Total 261 (delta 53), reused 130 (delta 19), pack-reused 0
Receiving objects: 100% (261/261), 440.99 KiB | 2.41 MiB/s, done.
Resolving deltas: 100% (53/53), done.
From https://github.com/AppOutlet/GameOutlet
* [new branch] main -> main
* [new tag] v1.0.1 -> v1.0.1
Initializing build dir
Committing stage init to cache
Starting build of io.github.appoutlet.GameOutlet
========================================================================
Building module openjdk in /home/messias/Workspace/flathub/.flatpak-builder/build/openjdk-1
========================================================================
Running: /usr/lib/sdk/openjdk17/install.sh
Committing stage build-openjdk to cache
========================================================================
Building module GameOutlet in /home/messias/Workspace/flathub/.flatpak-builder/build/GameOutlet-1
========================================================================
Switched to branch 'main'
Running: ./gradlew packageReleaseUberJarForCurrentOS
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Error: module GameOutlet: Child process exited with code 1