fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.12k stars 139 forks source link

Failed to load native library:jansi-2.4.0-1ba1a04f0d4ec9d-libjansi.so. osinfo: Linux/arm #251

Open somera opened 1 year ago

somera commented 1 year ago

Hi,

I see this

Failed to load native library:jansi-2.4.0-1ba1a04f0d4ec9d-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.0-1ba1a04f0d4ec9d-libjansi.so: /tmp/jansi-2.4.0-1ba1a04f0d4ec9d-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden

on my Raspis with 64bit OS.

[So Mai 28][13:57:32][pi]@[pi-manager]:[~]$ uname -a
Linux pi-manager 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux
[So Mai 28][14:02:38][pi]@[pi-manager]:[~]$ arch
aarch64

On 32bit it's all ok.

somera commented 1 year ago

I found #219, but i looks like it not fixed?

NoelJB commented 1 year ago

This appears to be a duplicate of https://github.com/termux/termux-packages/issues/8861. There is a downstream fix for that issue: https://github.com/termux/termux-packages/pull/9114, but it cannot be directly applied to the master branch, as their fix is for the 1.2.x branch.

gnodet commented 1 year ago

@NoelJB I don't think it's related @somera could you run java -jar jansi-2.4.0.jar and paste the output please ?

somera commented 1 year ago

On 32bit system it works:

[Sa Nov 04][12:32:57][pi]@[pi-devel]:[~]$ uname -a
Linux pi-devel 6.1.21-v7+ #1642 SMP Mon Apr  3 17:20:52 BST 2023 armv7l GNU/Linux
[Sa Nov 04][12:32:58][pi]@[pi-devel]:[~]$ mvn --version
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /data-files/tools/maven/apache-maven
Java version: 17.0.7, vendor: Raspbian, runtime: /usr/lib/jvm/java-17-openjdk-armhf
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "6.1.21-v7+", arch: "arm", family: "unix"

On 64bit system irn't working:

[Sa Nov 04][12:32:57][pi]@[pi-manager]:[~]$ uname -a
Linux pi-manager 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux
[Sa Nov 04][12:32:58][pi]@[pi-manager]:[~]$ mvn --version
Failed to load native library:jansi-2.4.0-a842779cd7f2baa1-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.0-a842779cd7f2baa1-libjansi.so: /tmp/jansi-2.4.0-a842779cd7f2baa1-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /data-files/tools/maven/apache-maven
Java version: 17.0.7, vendor: Raspbian, runtime: /usr/lib/jvm/java-17-openjdk-armhf
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "6.1.21-v8+", arch: "arm", family: "unix"
somera commented 1 year ago

@NoelJB I don't think it's related @somera could you run java -jar jansi-2.4.0.jar and paste the output please ?

Sorry for the late answer ...

here the output from my 64bit (Linux pi-manager 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux) system.

$ java -jar jansi-2.4.0.jar
Jansi 2.4.0

library.jansi.path=
library.jansi.version=
Failed to load native library:jansi-2.4.0-99b3a36a616fb93e-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.0-99b3a36a616fb93e-libjansi.so: /tmp/jansi-2.4.0-99b3a36a616fb93e-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
Failed to load native library:jansi-2.4.0-8e15b0951a96f8bb-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.0-8e15b0951a96f8bb-libjansi.so: /tmp/jansi-2.4.0-8e15b0951a96f8bb-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
java.lang.RuntimeException: Unable to load jansi native library. You may want set the `jansi.graceful` system property to true to be able to use Jansi on your platform
        at org.fusesource.jansi.internal.JansiLoader.initialize(JansiLoader.java:65)
        at org.fusesource.jansi.AnsiMain.main(AnsiMain.java:70)
Caused by: java.lang.Exception: No native library found for os.name=Linux, os.arch=arm, paths=[/org/fusesource/jansi/internal/native/Linux/arm:/usr/java/packages/lib:/usr/lib/arm-linux-gnueabihf/jni:/lib/arm-linux-gnueabihf:/usr/lib/arm-linux-gnueabihf:/usr/lib/jni:/lib:/usr/lib]
        at org.fusesource.jansi.internal.JansiLoader.loadJansiNativeLibrary(JansiLoader.java:334)
        at org.fusesource.jansi.internal.JansiLoader.initialize(JansiLoader.java:62)
        ... 1 more

os.name= Linux, os.version= 6.1.21-v8+, os.arch= arm
file.encoding= UTF-8
java.version= 17.0.7, java.vendor= Raspbian, java.home= /usr/lib/jvm/java-17-openjdk-armhf

jansi.graceful=
jansi.mode=
jansi.out.mode=
jansi.err.mode=
jansi.colors=
jansi.out.colors=
jansi.err.colors=
jansi.passthrough= false
jansi.strip= false
jansi.force= false
jansi.noreset= false
org.fusesource.jansi.Ansi.disable= false

IS_WINDOWS: false

Failed to load native library:jansi-2.4.0-7a50bc48482aee40-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.0-7a50bc48482aee40-libjansi.so: /tmp/jansi-2.4.0-7a50bc48482aee40-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
isatty(STDOUT_FILENO): 0, System.out is *NOT* a terminal
isatty(STDERR_FILENO): 0, System.err is *NOT* a terminal

Resulting Jansi modes for stout/stderr streams:
  - System.out: AnsiPrintStream{type=Unsupported, colors=Colors256, mode=Strip, resetAtUninstall=false}
  - System.err: AnsiPrintStream{type=Unsupported, colors=Colors256, mode=Strip, resetAtUninstall=false}
Processor types description:
  - Native: Supports ansi sequences natively
  - Unsupported: Ansi sequences are stripped out
  - VirtualTerminal: Supported through windows virtual terminal
  - Emulation: Emulated through using windows API console commands
  - Redirected: The stream is redirected to a file or a pipe
Colors support description:
  - Colors16: 16 colors
  - Colors256: 256 colors
  - TrueColor: 24-bit colors
Modes description:
  - Strip: Strip all ansi sequences
  - Default: Print ansi sequences if the stream is a terminal
  - Force: Always print ansi sequences, even if the stream is redirected

test on System.out: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
            bright: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
              bold: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
             faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        bold+faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        256 colors:

         truecolor: /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\
test on System.err: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
            bright: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
              bold: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
             faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        bold+faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        256 colors:

         truecolor: /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\

                      ┌──┐┌─────┐ ┌─────┐ ┌──────┬──┐
                      │██├┘█████└┬┘█████└┬┘██████│▐▌│
                 ┌──┐ │██│██▄▄▄██│██┌─┐██│██▄▄▄▄ │▄▄│
                 │▒▒└─┘▒█│▒█┌─┐▒█│▒█│ │▒█│ ▀▀▀▀▒█│▒█│
                 └┐▓▓▓▓▓┌┤▓▓│ │▓▓│▓▓│ │▓▓│▀▓▓▓▓▓▀│▓▓│
                  └─────┘└──┘ └──┴──┘ └──┴───────┴──┘
somera commented 1 year ago

And the output from 32bit system

[Sa Nov 04][12:41:04][pi]@[pi-devel]:[/tmp]$ uname -a
Linux pi-devel 6.1.21-v7+ #1642 SMP Mon Apr  3 17:20:52 BST 2023 armv7l GNU/Linux
[Sa Nov 04][12:41:08][pi]@[pi-devel]:[/tmp]$ java -jar jansi-2.4.0.jar
Jansi 2.4.0

library.jansi.path=
library.jansi.version=
Jansi native library loaded from /tmp/jansi-2.4.0-7cbe1583aeefa095-libjansi.so
   which was auto-extracted from jar:file:/tmp/jansi-2.4.0.jar!/org/fusesource/jansi/internal/native/Linux/armv7/libjansi.so

os.name= Linux, os.version= 6.1.21-v7+, os.arch= arm
file.encoding= UTF-8
java.version= 17.0.7, java.vendor= Raspbian, java.home= /usr/lib/jvm/java-17-openjdk-armhf

jansi.graceful=
jansi.mode=
jansi.out.mode=
jansi.err.mode=
jansi.colors=
jansi.out.colors=
jansi.err.colors=
jansi.passthrough= false
jansi.strip= false
jansi.force= false
jansi.noreset= false
org.fusesource.jansi.Ansi.disable= false

IS_WINDOWS: false

isatty(STDOUT_FILENO): 1, System.out is a terminal
isatty(STDERR_FILENO): 1, System.err is a terminal

Resulting Jansi modes for stout/stderr streams:
  - System.out: AnsiPrintStream{type=Native, colors=Colors256, mode=Default, resetAtUninstall=true}
  - System.err: AnsiPrintStream{type=Native, colors=Colors256, mode=Default, resetAtUninstall=true}
Processor types description:
  - Native: Supports ansi sequences natively
  - Unsupported: Ansi sequences are stripped out
  - VirtualTerminal: Supported through windows virtual terminal
  - Emulation: Emulated through using windows API console commands
  - Redirected: The stream is redirected to a file or a pipe
Colors support description:
  - Colors16: 16 colors
  - Colors256: 256 colors
  - TrueColor: 24-bit colors
Modes description:
  - Strip: Strip all ansi sequences
  - Default: Print ansi sequences if the stream is a terminal
  - Force: Always print ansi sequences, even if the stream is redirected

test on System.out: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
            bright: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
              bold: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
             faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        bold+faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        256 colors:

         truecolor: /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\
test on System.err: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
            bright: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
              bold: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
             faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        bold+faint: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE DEFAULT
        256 colors:

         truecolor: /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                    /\/\/\/\/\/\/\/\

                      ┌──┐┌─────┐ ┌─────┐ ┌──────┬──┐
                      │██├┘█████└┬┘█████└┬┘██████│▐▌│
                 ┌──┐ │██│██▄▄▄██│██┌─┐██│██▄▄▄▄ │▄▄│
                 │▒▒└─┘▒█│▒█┌─┐▒█│▒█│ │▒█│ ▀▀▀▀▒█│▒█│
                 └┐▓▓▓▓▓┌┤▓▓│ │▓▓│▓▓│ │▓▓│▀▓▓▓▓▓▀│▓▓│
                  └─────┘└──┘ └──┴──┘ └──┴───────┴──┘
somera commented 1 year ago

image

billfor commented 1 year ago

This is because jansi uses a common OSInfo.java which, according to the raspberry pi people, does not properly determine the architecture, so the JNI library will be 64 bit on a 32bit userland raspberry pi.

Anyone that has a raspberrypi4 and does an apt upgrade will suddenly have their kernel updated to 64 bit, but userland remains 32 bit.

According the raspberrpy pi people in https://github.com/raspberrypi/firmware/issues/1795, you should use getconf LONG_BITand not uname -mto determine the architecture of the JNI to load.

At least with the jdbc-sqlite people, they provide a means to override the decision of the software with a system property. In their version of osinfo you have. https://github.com/xerial/sqlite-jdbc/blob/master/src/main/java/org/sqlite/util/OSInfo.javaL#235 which does something like this:

        String override = System.getProperty("org.sqlite.osinfo.architecture");
        if (override != null) {
            return override;
        }

So for jansi I would suggest that you do something simlar in https://github.com/fusesource/jansi/blob/master/src/main/java/org/fusesource/jansi/internal/OSInfo.java to allow raspberry pi users to override it. The current behavior does not determine the architure properly and gives the user no way to override it. If you are on a system that returns the following:

root@rpi4:~#uname -m
aarch64
root@rpi4:~#getconf LONG_BIT
32

Which is any 64bit raspberry pi that was installed before the 64 bit switch, and was routinely upgraded. You can argue with the raspberry pi people in https://github.com/raspberrypi/firmware/issues/1795, but at least provide an option to override because the current logic is broken.

Also see https://github.com/xerial/sqlite-jdbc/issues/1012 which is the same issue.

I can submit a fix if code owners are busy but I don't really work on this project. I just want the error message to stop.

somera commented 4 months ago

Any idea how to fix this?

$ mvn --version
Failed to load native library:jansi-2.4.1-49d6f2a8579df447-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.1-49d6f2a8579df447-libjansi.so: /tmp/jansi-2.4.1-49d6f2a8579df447-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /data-files/to$ mvn --version
Failed to load native library:jansi-2.4.1-49d6f2a8579df447-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.1-49d6f2a8579df447-libjansi.so: /tmp/jansi-2.4.1-49d6f2a8579df447-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /data-files/tools/maven/apache-maven
Java version: 17.0.11, vendor: Eclipse Adoptium, runtime: /usr/lib/jvm/temurin-17-jdk-armhf
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "6.1.21-v8+", arch: "arm", family: "unix"ols/maven/apache-maven
Java version: 17.0.11, vendor: Eclipse Adoptium, runtime: /usr/lib/jvm/temurin-17-jdk-armhf
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "6.1.21-v8+", arch: "arm", family: "unix"
krufab commented 2 months ago

@somera, This worked for me, on a Jenkins agent:

# in your pipeline, create a local temp folder
mkdir tmp
# export this flag (it's the only way maven interpreted it)
export MAVEN_OPTS="-Djansi.tmpdir=./tmp"
# run the maven command
mvn clean deploy

For more info on passing flags to the JVM: https://www.baeldung.com/java-maven-pass-jvm-arguments

somera commented 2 months ago

@somera, This worked for me, on a Jenkins agent:

I'm using it in the bash.

export MAVEN_OPTS="-Djansi.tmpdir=./tmp"

[Do Sep 05][16:55:23][pi]@[pi-manager]:[~]$ echo $MAVEN_OPTS
-Djansi.tmpdir=/tmp

[Do Sep 05][16:55:31][pi]@[pi-manager]:[~]$ mvn --version
Failed to load native library:jansi-2.4.1-b48a4847e57ec94e-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /tmp/jansi-2.4.1-b48a4847e57ec94e-libjansi.so: /tmp/jansi-2.4.1-b48a4847e57ec94e-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /data-files/tools/maven/apache-maven
Java version: 17.0.12, vendor: Eclipse Adoptium, runtime: /usr/lib/jvm/temurin-17-jdk-armhf
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "6.1.21-v8+", arch: "arm", family: "unix"
krufab commented 1 month ago

@somera, check if the filesystem is writable: i.e. you could have a FS which is mounted read only. It's a bit unlikely for /tmp, but check with findmnt: https://www.baeldung.com/linux/filesystem-check-permissions Or try to have the jansi.tmpdir in the home of the user as I did.

somera commented 1 month ago

@krufab my /tmp is writable

$ findmnt -n -o OPTIONS /
rw,noatime
$ ls -al /tmp/
insgesamt 40K
drwxrwxrwt 10 root root 4,0K 21. Sep 09:54 ./

And I checked your way:

$ pwd
/home/pi/data-files/microservices/raspi_mail_service
$ mkdir tmp
$ echo $MAVEN_OPTS
-Djansi.tmpdir=./tmp
$ alias mci
alias mci='mvn clean install'
$ mci
Failed to load native library:jansi-2.4.1-b43886c12d33d1a6-libjansi.so. osinfo: Linux/arm
java.lang.UnsatisfiedLinkError: /data-files/microservices/raspi_mail_service/tmp/jansi-2.4.1-b43886c12d33d1a6-libjansi.so: /data-files/microservices/raspi_mail_service/tmp/jansi-2.4.1-b43886c12d33d1a6-libjansi.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
[INFO] Scanning for projects...
[INFO]

As you can see. Same error.

I have this problem only on aarch64.

somera commented 1 month ago

And what happens to:

https://github.com/fusesource/jansi/issues/251#issuecomment-1802479072

I can submit a fix if code owners are busy but I don't really work on this project. I just want the error message to stop.

Did that happen?