JavaFX snap launch crashes


#1

OK, SNAP and JavaFX Newbie time … :grinning::rofl:

//==========================================
My Issue
I’m using a book standard HelloWorld JavaFX app compiled on IntelliJ IDE, using the gradle installDist command
This produces a .zip file with the JavaFX libs and HelloWorld.jar in a /bin directory and a couple of scripts for linux and windows. Rathder than set the all ENV variables in in the snapcraft.yaml file I have introduced a buffer script called by the comand-helloworld.wrapper that sets some env variables, which execs to the startup script in the helloworld/bin directory which calls java.

Creating the snap works fine. Installing the snap is fine. Executing the snap fails during the launch. (stacktrace below).

If I unpack the snap (helloworld_0.1_and64.snap) within a directory in my standard OS, it executes fine. If I package the HelloWorld.Zip file and my buffer script (removing $SNAP prefix from the paths) as a .DEB package, and then install it on my dev system, it runs fine.

The jre pulled into the snap appears to be the same as the one used within my dev system, and the relevent JavaFX libs seem to be there as well i.e:
javafx-base-11.jar
javafx-base-11-linux.jar
javafx-controls-11.jar
javafx-controls-11-linux.jar
javafx-fxml-11-linux.jar
javafx-graphics-11.jar
javafx-graphics-11-linux.jar

I’m at my wits end with this one. Everything seems to be in place, but the launch of the snap is failing within the Java launch with the error:
Exception in thread “main” java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at … {on for several lines}

Caused by: java.lang.UnsupportedOperationException: Internal Error
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:189)
at … {on for several lines}

There may be some differnce between the environment of my dev system and the snap environment, but I just cannot see it.
I woudl be grateful for any pointers.

Many Thanks
Alan
Full details below!

//======================================
My Development Environment:

Ubuntu18:04
IntelliJ Community 2019.2
snapcraft, version 2.43.1+18.4
snap version:
snap 2.41
snapd 2.41
series 16
ubuntu 18.04
kernel 4.15.0-62-generic
java-11-openjdk-amd64, also used for build within IntelliJ,
=> java --version
openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
=> javac --version
javac 11.0.4

//=========================================
snapcraft.yaml:

name: helloworld # you probably want to 'snapcraft register ’

version: ‘0.1’ # just for humans, typically ‘1.2+git’ or ‘1.3.2’
summary: Helloworld app # 79 char long summary
description: |
First try at a snap

grade: devel # must be ‘stable’ to release into candidate/stable channels
confinement: devmode # use ‘strict’ once you have the right plugs and slots

base: core18

parts:
helloworld:

plugin: nil
source: .
override-build: |
   unzip HelloWorld.zip -d $SNAPCRAFT_PART_INSTALL/
build-packages:
  - unzip
stage-packages:
  - openjdk-11-jre
  - ca-certificates-java

apps:
helloworld:
command: HelloWorld/HelloWorld.sh

//===========================================
snap.yaml:
name: helloworld
version: ‘0.1’
summary: Helloworld app
description: 'First try at a snap


base: core18
architectures:

  • amd64
    confinement: devmode
    grade: devel
    apps:
    helloworld:
    command: command-helloworld.wrapper

//===========================================
command-helloworld.wrapper:
#!/bin/sh
export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu"
export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH
exec “$SNAP/HelloWorld/HelloWorld.sh” “$@”
//===========================================
HelloWorld.sh. This script was written by myself to aid in debugging

#!/usr/bin/env sh

buffer startup script for HelloWorld

echo found HelloWorld.sh
echo Path1 = $PATH
echo
echo Java Home1 = $JAVA_HOME
echo
echo Snap = $SNAP
echo
export JAVA_HOME=$SNAP$JAVA_HOME
export Path=$JAVA_HOME/jre/bin:$PATH
export LD_LIBRARY_PATH=$SNAPHelloWorld/lib:$LD_LIBRARY_PATH
echo Path2 = $PATH
echo $LD_LIBRARY_PATH
echo
echo Java Home2 = $JAVA_HOME
exec $SNAP/HelloWorld/bin/HelloWorld

//============================================
HelloWorld startup script - this is generated by Intellij, I have added a few debug lines to help me see what is happening

#!/usr/bin/env sh

##############################################################################

HelloWorld start up script for UN*X

##############################################################################

Attempt to set APP_HOME

Resolve links: $0 may be a link

PRG="$0"

Need this for relative symlinks.

while [ -h “$PRG” ] ; do
ls=ls -ld "$PRG"
link=expr "$ls" : '.*-> \(.*\)$'
if expr “$link” : ‘/.*’ > /dev/null; then
PRG="$link"
else
PRG=dirname "$PRG""/$link"
fi
done
SAVED="pwd"
cd “dirname \"$PRG\"/…” >/dev/null
APP_HOME="pwd -P"
cd “$SAVED” >/dev/null

APP_NAME=“HelloWorld”
APP_BASE_NAME=basename "$0"

Add default JVM options here. You can also use JAVA_OPTS and HELLO_WORLD_OPTS to pass JVM options to this script.

DEFAULT_JVM_OPTS=’"–module-path" “$APP_HOME/lib” “–module” “HelloWorld.main/com.dryjointproductions.ghelloworld.HelloWorld”’

Use the maximum available, or set MAX_FD != -1 to use that value.

MAX_FD=“maximum”

warn () {
echo “$*”
}

die () {
echo
echo “$*”
echo
exit 1
}

OS specific support (must be ‘true’ or ‘false’).

cygwin=false
msys=false
darwin=false
nonstop=false
case “uname” in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=

Determine the Java command to use to start the JVM.

if [ -n “$JAVA_HOME” ] ; then
if [ -x “$JAVA_HOME/jre/sh/java” ] ; then
# IBM’s JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
#mod by apdw
JAVAVERSCMD="$JAVA_HOME/bin/java --version"
fi

mods by apdw

echo Java Home in HWorld = $JAVA_HOME
echo JavaCmd = $JAVACMD
if [ ! -x "$JAVACMD" ] ; then
  die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=“java”
which java >/dev/null 2>&1 || die "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."
fi

Increase the maximum file descriptors if we can.

if [ “$cygwin” = “false” -a “$darwin” = “false” -a “$nonstop” = “false” ] ; then
MAX_FD_LIMIT=ulimit -H -n
if [ $? -eq 0 ] ; then
if [ “$MAX_FD” = “maximum” -o “$MAX_FD” = “max” ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn “Could not set maximum file descriptor limit: $MAX_FD”
fi
else
warn “Could not query maximum file descriptor limit: $MAX_FD_LIMIT”
fi
fi

For Darwin, add options to specify how the application appears in the dock

if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS “-Xdock:name=$APP_NAME” “-Xdock:icon=$APP_HOME/media/gradle.icns”"
fi

For Cygwin, switch paths to Windows format before running java

if $cygwin ; then
APP_HOME=cygpath --path --mixed "$APP_HOME"
CLASSPATH=cygpath --path --mixed "$CLASSPATH"
JAVACMD=cygpath --unix "$JAVACMD"

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
    ROOTDIRS="$ROOTDIRS$SEP$dir"
    SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
    OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
    CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
    CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option

    if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
        eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
    else
        eval `echo args$i`="\"$arg\""
    fi
    i=$((i+1))
done
case $i in
    (0) set -- ;;
    (1) set -- "$args0" ;;
    (2) set -- "$args0" "$args1" ;;
    (3) set -- "$args0" "$args1" "$args2" ;;
    (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
    (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
    (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
    (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
    (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
    (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac

fi

Escape application args

save () {
for i do printf %s\n “$i” | sed “s/’/’\\’’/g;1s/^/’/;$s/$/’ \\/” ; done
echo " "
}
APP_ARGS=$(save “$@”)

Collect all arguments for the java command, following the shell quoting and substitution rules

eval set – $DEFAULT_JVM_OPTS $JAVA_OPTS $HELLO_WORLD_OPTS -classpath “”$CLASSPATH"" com.dryjointproductions.ghelloworld.HelloWorld “$APP_ARGS”

by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong

if [ “$(uname)” = “Darwin” ] && [ “$HOME” = “$PWD” ]; then
cd “$(dirname “$0”)”
fi
$JAVAVERSCMD >helloworldlaunch.txt >helloworldlaunch.txt
exec “$JAVACMD” -verbose “$@” >>helloworldlaunch.txt

//============================================
Stacktrace:

Exception in thread “main” java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.UnsupportedOperationException: Internal Error
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:189)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.(GtkApplication.java:171)
at javafx.graphics/com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
at javafx.graphics/com.sun.glass.ui.Application.run(Application.java:144)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:258)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
… 5 more
//===============================================