Java spring-shell-standard cli program failed to perform only under Snap

Hi all! I have a Java cli program that uses the spring-shell-standard library. Some of the features of this library is to auto complete shell command and changing the color of the text.

Everything worked fine until lately, we discovered that new snap versions we build are not working as usual (old snap versions we already built in the past still working fine).

When I running it not under Snap, everything works.

The only things we changed in the way we build our snap is: Added to the snapcraft yaml base:core18 due to a change in snapcraft that requires this setting. And running the snapcraft with --use-lxd due to an multipass error. According to the following:

also tried with --provider=host --destructive-mode

Please help, Thanks in advance!

I have created a simple example and I payed attention that the spring-shell-standard uses jline-terminal is throwing a warning only when it’s running under snap.

WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)

This warning can explain why I experience lack of special features, such as bold and blinking characters.

But why it “Unable to create a system terminal” under Snap? see: https://github.com/jline/jline3/blob/a01fe264d43ecdf7ab969d4a431cec3f8f840986/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java

Thanks!

After some debugging, I got the specific error:

WARNING: Creating a dumb terminal
java.lang.IllegalStateException: Unable to create a system terminal
        at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:219)
        at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:172)
            at App.main(App.java:29)
        Suppressed: java.lang.NoClassDefFoundError: com/sun/jna/Platform
                at org.jline.terminal.impl.jna.JnaNativePty.current(JnaNativePty.java:39)
                at org.jline.terminal.impl.jna.JnaSupportImpl.current(JnaSupportImpl.java:15)
                at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:260)
                ... 2 more
        Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
                at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
                at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
                at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
                ... 5 more
        Suppressed: java.lang.UnsupportedOperationException
                at org.jline.terminal.impl.jansi.JansiSupportImpl.current(JansiSupportImpl.java:70)
                at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:270)
                ... 2 more
        Suppressed: java.io.IOException: Not a tty
                at org.jline.terminal.impl.ExecPty.current(ExecPty.java:44)
                at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:279)
                ... 2 more
        Caused by: java.io.IOException: Error executing 'tty': not a tty
                at org.jline.utils.ExecHelper.exec(ExecHelper.java:42)
                at org.jline.terminal.impl.ExecPty.current(ExecPty.java:41)
                ... 3 more

Also, when I’m running snap run --shell <SnapName> and run tty command I’m getting “not a tty”. What is the reason? does it changed lately?

Thanks!

Solved by adding to the command < /dev/tty e.g java -jar myjar.jar < /dev/tty