Help me with packaging a Java program using the libwebkit2gtk-4.0-37 package

I was forced to update the version of the operating system to Ubuntu 20.04 on the build server. Using ‘base: core20’ in snapcraft.yaml

I have a problem with hardcoded paths in the library.

Unable to fork a new WebProcess: Failed to execute child process “/usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebKitNetworkProcess” (No such file or directory)`

As I understand the developers, it is recommended to use snapcraft-preload in the snapcraft.yaml file

snapcraft-preload:
    source: https://github.com/sergiusens/snapcraft-preload.git
    plugin: cmake
    cmake-parameters:
        - -DCMAKE_INSTALL_PREFIX=/usr
    build-packages:
        - on amd64:
            - gcc-multilib
            - g++-multilib

Inside my run.sh startup script (adapted copy of desktop-launch) there are lines

append_dir LD_LIBRARY_PATH $SNAP/usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/

if [ -f $SNAP/usr/lib/libsnapcraft-preload.so ]; then
    export LD_PRELOAD=$LD_PRELOAD:$SNAP/usr/lib/libsnapcraft-preload.so
fi

$SNAP/usr/bin/snapcraft-preload $SNAP/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java bla-bla-bla-java-jar

If you install the snap package and call the program for the first time

ERROR: ld.so: object ‘/snap/my-java-app/x1/lib/libsnapcraft-preload.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

** (my-java-app:142669): ERROR **: 16:24:59.347: Unable to fork a new child process: Failed to execute child process “/usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebKitNetworkProcess” (No such file or directory)

Second launch and the program starts normally.

ERROR: ld.so: object ‘/snap/my-java-app/x1/lib/libsnapcraft-preload.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

Help solve the problem correctly.

From what I can tell, the snapcraft_preload from the linked bug report was probably suggested because layouts didn’t exist at the time, so I think you can avoid using the preloads for this problem in 2021.

The gnome extensions would solve the webkit problem for you. They do it by (sneakily) adding:

layout:
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/webkit2gtk-4.0:
    bind: $SNAP/gnome-platform/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/webkit2gtk-4.0

to your snapcraft.yaml, if you’re not using the Gnome extensions already I’d suggest giving them a go, they usually work transparently with Java applications. https://snapcraft.io/docs/snapcraft-extensions

You could probably add the layout above into the snapcraft.yaml by itself though if you wanted though, but there might be other things that the extensions do in their own desktop-launch that might tie it all together.

Thank you very much!