Issue with Java -> Desktop.browse, "BROWSE action is not supported "

Hi!

I try to snap UMLet’s standalone .jar-file. Everything works fine except for opening links. If I run the application with debugging enabled I see that there is an issue with java.awt.Desktop.checkActionSupport that claims that java.awt.Desktop.browse is not supported.

java.lang.UnsupportedOperationException: The BROWSE action is not supported on the current platform!
at java.desktop/java.awt.Desktop.checkActionSupport(Desktop.java:380)
at java.desktop/java.awt.Desktop.browse(Desktop.java:524)

This issue seems to bother others as well:

@popey seems to have found a solution for Minecraft but the description was a bit vague “[…]Added further stage packages to ensure clicking links work in most desktops[…]”

Things I tried:

  • Add stage-package libgnome-2-0 (core18 since not available for core20)
  • Add stage-package gvfs and add ${SNAP}/usr/lib/x86_64-linux-gnu/gvfs to LD_LIBRARY_PATH
  • Set environment GTK_USE_PORTAL: 1
  • core18, core20
  • Different versions of Java
  • snappy-debug shows nothing if I click on a link

Since I just have the jar-file I can’t change to using xdg-open

If I run it from the host directly (Ubuntu 20.04) it works without issues so I guess I miss some import (or the Gnome-extension might miss something) …

snapcraft.yaml

Personally I use the Java Module functionality to override the class that controls this behaviour on Linux. Take a look at https://github.com/MrCarroll/runescape-snap/tree/master/osrs/java-patches.

Put that file (and patch source? I’m not a lawyer, but Java is GPL so caveat emptor) in your snap and then pass Java the flag to use it

java --patch-module java.desktop=$SNAP/java-patches/compiled/java.desktop

Please note that while the leading path doesn’t matter, the trailing part of the path must be java.desktop/sun/awt/X11

The advantage of this approach is that as Java security updates are pushed via the standard Ubuntu repository, you can simply update to them for free, since you don’t have to rebuild Java every time for this one patch as it’s dynamically done at runtime.

Note: I’ve only tested this on Java 11, you might need to rebuild the .class file for other versions of Java, and with it using the Java Module system, it demands at least Java 9.

If you were wondering how to generate the .class file itself, since javac won’t do it. It’s effectively apt source openjdk-11-jre, swapping the .java files out, building the Ubuntu JRE with the modification with the standard debian build tools, then extracting the .class file from the build directory before it’s packed. Not exactly amazing, but the end result works.

1 Like

Works! :+1:

Thank you! :man_mechanic:

UMLet will be fixed in the next release to use xdg-open so I won’t need James’ solution in the near future.

In case someone needs to implement it, I’m documenting a minimal example of what I did to make it work here:

  • Copy everything under https://github.com/MrCarroll/runescape-snap/tree/master/osrs/java-patches to my repository

  • Add (at least) this override-build to my snapcraft.yaml

     override-build: |      
         wget https://github.com/digidigital/UMLet-snap/raw/main/java-patches/compiled/java.desktop/sun/awt/X11/XDesktopPeer.class
         mkdir -p ${SNAPCRAFT_PART_INSTALL}/Umlet/java-patches/compiled/java.desktop/sun/awt/X11
         mv XDesktopPeer.class ${SNAPCRAFT_PART_INSTALL}/Umlet/java-patches/compiled/java.desktop/sun/awt/X11/XDesktopPeer.class
    
  • Create an executable launch script e.g. “launch.sh” in ${SNAPCRAFT_PART_INSTALL}/Umlet/ (Java was added to PATH)

    #!/bin/bash
    java --patch-module java.desktop=$SNAP/Umlet/java-patches/compiled/java.desktop -Duser.home=$SNAP_USER_DATA
    
  • Make launch script “command” of the main part in snapcraft.yaml

     apps:
       umlet-standalone:
          command: Umlet/launch.sh
    

If you pull the whole repository with “dump” your snapcraft.yaml will look a bit different (e. g. no wget). My snapcraft.yaml just downloads a zip-file with a jar-file and the Java module…