fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 133 forks source link

Linux executable doesn't start if under a path with spaces #214

Closed salmonb closed 2 years ago

salmonb commented 2 years ago

I'm submitting a…

Short description of the issue/suggestion:

If the path to the repository contains spaces, the Linux executable generated by Javapackager doesn't start.

Steps to reproduce the issue/enhancement:

  1. Create a directory with spaces (ex: mkdir My\ Projects)
  2. Move the project under that directory
  3. Try to run the executable generated by Javapackager

What is the expected behavior?

The executable should run, whether or not there are spaces in the path

What is the current behavior?

The executable fails to run when there are spaces in the path

Do you have outputs, screenshots, demos or samples which demonstrate the problem or enhancement?

$ /home/bruno/My\ Projects/myproject/mymodule/target/javapackager/MyApp/MyApp
/home/bruno/My Projects/myproject/mymodule/target/javapackager/MyApp/MyApp: line 13: [: /home/bruno: binary operator expected
/home/bruno/My Projects/myproject/mymodule/target/javapackager/MyApp/MyApp: line 17: cd: $'/home/bruno\nProjects/myproject/mymodule/target/javapackager/MyApp': No such file or directory
/home/bruno/My Projects/myproject/mymodule/target/javapackager/MyApp/MyApp: line 20: /home/bruno: Is a directory

What is the motivation / use case for changing the behavior?

Just make it works :)

Please tell us about your environment:

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

fvarrui commented 2 years ago

Hi @salmonb! Sorry for my late reply ... I've been traveling last week.

Please, can you share here the generated startup script for Linux? (it should be in target/assets/startup.sh)

Thanks!

salmonb commented 2 years ago

hi @fvarrui

Here is the content of startup.sh

#!/usr/bin/env bash
# GNU/Linux startup script generated by JavaPackager plugin

SCRIPTPATH=$(dirname $(readlink -e "$0"))

JAVA="$SCRIPTPATH/jre/bin/java"

BINARY="$SCRIPTPATH/WebFXExample"

JVMDefaultOptions=""
JVMOptionsFile="$SCRIPTPATH/WebFXExample.l4j.ini"
[ -f $JVMOptionsFile ] && while read -r option; do JVMDefaultOptions+=" $option"; done <<< $(sed "/^#.*$/d" $JVMOptionsFile)

JVMClassPath="$BINARY"

cd "$SCRIPTPATH"

$JAVA $JVMDefaultOptions -cp $JVMClassPath dev.webfx.platform.boot.ApplicationBooter $@
exit 0

If I run this script under a path with a space (ex: /home/bruno/dev/javapackager\ issue/... <= there is a space between javapackager and issue), then I'm getting this error:

./startup.sh: line 13: [: /home/bruno/dev: binary operator expected
./startup.sh: line 17: cd: $'/home/bruno/dev\nissue/webfx-example-application-openjfx/target/javapackager/assets': No such file or directory
fvarrui commented 2 years ago

Yes, thank you! I'm working on it ... I've just reproduced your issue and find out that the problem is in this line:

SCRIPTPATH=$(dirname $(readlink -e "$0"))

Just adding doublequotes and the problem is fixed:

SCRIPTPATH=$(dirname "$(readlink -e "$0")")

Notice the double quotes

I've just released the change in issue-214 branch ... please, try it and give me some feedback. I'd like to include this fix in v1.6.7.

fvarrui commented 2 years ago

AppImage generation feature is already included ... as you are trying on Linux, would you mind trying the AppImage binary too?

salmonb commented 2 years ago

Great, glad that you found a fix :smiley:

I'm happy to test, but not sure how, as I never used a Maven plugin other than by listing it on my pom.xml...

I cloned your repository and checked out the issue-214 branch, but how can I tell Maven to use it now? I'm not used to Maven plugin development, sorry...

fvarrui commented 2 years ago

Hi @salmonb!

You can build JavaPackager on your own by running next commands:

git clone https://github.com/fvarrui/JavaPackager --branch issue-214
cd JavaPackager
./gradlew publishToMavenLocal

Last command will install the plugin in your local repo (inside .m2 directory) ... and that's all! Now you can use this version of the plugin. Just set 1.6.7-SNAPSHOT as JavaPackager version in your POM.

I'm using Java 11 because newer versions cause problems with Gradle 6 (yes! I have to upgrade Gradle, but it requires time as some plugins used in the building process are no longer available in newer versions 😓)

salmonb commented 2 years ago

hi @fvarrui

Thank you, I managed to test your SNAPSHOT version by following your instructions :+1:

I confirm that the Linux executable now starts correctly, good job! :smile:

For the AppImage generation, some lines are logged as [ERROR] while they seem to be just [INFO], is it normal?

[INFO]         Executing command: /bin/sh -c cd '/home/bruno/dev/webfx example/.' && 'cp' "/home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/assets/WebFXExample.png" "/home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/assets/AppDir/WebFXExample.png"
[INFO]         Running appimagetool on /home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/WebFXExample
[INFO]         Executing command: /bin/sh -c cd '/home/bruno/dev/webfx example/.' && '/home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/assets/appimagetool' --appimage-extract-and-run "/home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/assets/AppDir" "/home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/WebFXExample.AppImage"
[ERROR]         appimagetool, continuous build (commit 8bbf694), build <local dev build> built on 2020-12-31 11:48:33 UTC
[INFO]         /home/bruno/dev/webfx example/webfx-example-application-openjfx/target/javapackager/assets/AppDir/WebFXExample.desktop: warning: value "WebFX Example" for key "Comment" in group "Desktop Entry" looks redundant with value "WebFX Example" of key "Name"
[ERROR]         Using architecture x86_64
[ERROR]         Deleting pre-existing .DirIcon
[ERROR]         Creating .DirIcon symlink based on information from desktop file
[ERROR]         WARNING: AppStream upstream metadata is missing, please consider creating it
[ERROR]                  in usr/share/metainfo/WebFXExample.appdata.xml
[ERROR]                  Please see https://www.freedesktop.org/software/appstream/docs/chap-Quickstart.html#sect-Quickstart-DesktopApps
[ERROR]                  for more information or use the generator at http://output.jsbin.com/qoqukof.
[ERROR]         Generating squashfs...

In the end the WebFXExample.AppImage executable file is generated. But when I try to execute it, I'm getting:

dlopen(): error loading libfuse.so.2

AppImages require FUSE to run. 
You might still be able to extract the contents of this AppImage 
if you run it with the --appimage-extract option. 
See https://github.com/AppImage/AppImageKit/wiki/FUSE 
for more information

Is it a normal requirement to install FUSE to execute AppImages?

fvarrui commented 2 years ago

Is it a normal requirement to install FUSE to execute AppImages?

Yes, are you testing on WSL? Because I got same error. I've tried on LinuxMint and it seems to be working fine. 🤷‍♂️

Here you can find instructions and why AppImage uses FUSE.

fvarrui commented 2 years ago

Branch issue-214 merged into devel.

salmonb commented 2 years ago

are you testing on WSL?

No, I'm on Ubuntu 22.04. FUSE is already installed but it's FUSE 3, and the AppImage requires FUSE 2. It's possible to install FUSE 2 beside FUSE 3, which I did, and then the AppImage is running :+1:

Do you know if there could be an option to choose the FUSE version when generating the AppImage?

Branch issue-214 merged into devel.

Great job :partying_face:

fvarrui commented 2 years ago

JavaPackager v1.6.7 released to Maven Central. See changes here.