JNA native support (/com/sun/jna/linux-arm/libjnidispatch.so) not found in resource path
Solution 1
I am re-compiling Apache Spark for RPI2 and I've spent a couple of days to fix the issue. Then I've found the easiest possible solution. All you need to have is a libjnidispatch.so link in your default JVM's native lib path.
sudo -s ln -s /usr/lib/arm-linux-gnueabihf/jni/libjnidispatch.so /usr/lib/jvm/default-java/jre/lib/arm/libjnidispatch.so
Solution 2
Where is libjnidispatch.so on your system? If it's not on your system, JNA will attempt to unpack it from jna.jar from the indicated resource path. If it's not there either, you'll get the UnsatisfiedLinkError
.
It's recommended that you explicitly install libjnidispatch.so on your system where possible; the jna.jar bundling is mostly there to facilitate usage on the more common desktop platforms.
linux-arm.jar
contains the most recent build of libjnidispatch.so, but only WebStart knows how to automatically load the native from a jar like that. If you unpack it into /opt/lib/jna (or elsewhere on LD_LIBRARY_PATH), you should avoid the link error.
Solution 3
I packaged the new jna.jar (4.0) and it includes the linux-arm/libjnidispatch.so. The code I was trying to run now works.
Pär Fransman
Updated on September 01, 2020Comments
-
Pär Fransman over 3 years
I have started to build a java service which incorporates JNA to load a native C/C++ lib and i want to run the java service on the Raspberry PI aka arm platform. I have successfully built a stable ground of the service and it runs on both Windows7 and linux-amd64/debian but.. on the RPI platform i get the above stated error: Exception in thread "main" java.lang.UnsatisfiedLinkError: JNA native support (/com/sun/jna/linux-arm/libjnidispatch.so) not found in resource path
On the RPI i have done the following: * Installed both openjdk7 and java8 beta with arm hard float support. * Installed libjna-java lib.
Following are set:
Java
root@pisces:/opt/TellstickReplay# java -version java version "1.8.0-ea" Java(TM) SE Runtime Environment (build 1.8.0-ea-b36e) Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode) root@pisces:/opt/TellstickReplay#
LD_LIBRARY_PATH
root@pisces:/opt/TellstickReplay# echo $LD_LIBRARY_PATH /opt/lib/jna
CLASSPATH
root@pisces:/opt/TellstickReplay# echo $CLASSPATH /usr/lib/jna
None of the settings seems to satisfy JAVA with JNA support. I have even tried to export both jna.jar and linux-arm.jar into the project in Eclipse and all together rebuild the jars into the exported jar still getting the same error. The exported jar has been tested successfully on both windows and linux so the jar file is working.
I have also tried to just use CLASSPATH in the Manifest in the jar file but with no success. I have also tried to explicitly load the libjnidispatch.so from the absolute path but JAVA then starts to complain that it cannot find the file to libjnidispatch.so even that the path is 100% correct.
So.. does anyone know HOW to correctly get JNA support on the Raspberry PI platform to work?? Please, im getting tremendously frustrated and soon giving up hope to fix this..
-
Pär Fransman over 11 yearsthe libjnidispatch.so is both in the CLASSPATH, LD_LIBRARY_PATH and on the filesystem in /usr/libs/jna.
-
technomage over 11 yearsThe error message indicates that JNA has tried to unpack it from jna.jar after unsuccessfully loading via
System.loadLibrary()
. You can set the system propertyjna.boot.library.path
to /usr/libs/jna, but you shouldn't have to if LD_LIBRARY_PATH already includes that path (note that in your question you have it set to /*opt/lib*/jna, which will result in an error if the library is actually in /*usr/libs*/jna). -
Pär Fransman over 11 yearsYou mention System.loadLibrary() though i have read about JNA using Native.loadLibrary() but looking through jna i can´t find System.loadLibrary(). Is there a significant difference between these two??
-
Pär Fransman over 11 yearsAlso is there a Raspbian image that have JNA working out of the box? I have been searching for a solution for this for so long i cant really motivate finding the source for this.
-
Pär Fransman over 11 yearsim trying to load a C library:
this.libTelldus = (CLibrary)Native.loadLibrary("telldus-core", CLibrary.class);
but i keep getting constantUnsatisfiedLinkError
all the time. I have changed the LD_LIBRARY_PATH to /opt/lib/jna and CLASSPATH to /opt/lib/jna and trying to use -Djna.boot.library.path=/opt/lib/jna. -
Pär Fransman over 11 yearsException in thread "main" java.lang.UnsatisfiedLinkError: JNA native support (/com/sun/jna/linux-arm/libjnidispatch.so) not found in resource path
-
technomage over 11 yearsJNA uses System.loadLibrary() within Native.loadLibrary(). Does /opt/lib/jna/libjnidispatch.so exist and is it a valid linux-arm shared library? You can build jna.jar yourself on a self-hosted linux-arm platform (you could probably cross-compile, but that'd take some configuration tweaking of the build.xml and Makefile). I would guess, though that the debian linux-arm build should be perfectly compatible with the raspberry pi.
-
Pär Fransman over 11 yearsYes i have placed the libjnidispatch.so in /op/lib/jna but what i dont understand if its linked or not. Should there be a symlink to /usr/lib? So it could be that im missing the libjnidispatch.so as a shared library??
-
Pär Fransman over 11 yearsHave i placed the .so file in the wrong directory? Should it be placed elsewere? Or is it possible to load the damn lib from java so it knows its there???
-
technomage over 11 yearsIt should be possible to load libjnidispatch.so from anywhere. What does
file libjnidispatch.so
report? -
Pär Fransman over 11 yearshmm it didnt report anything actually. shouldnt be a symlink showing?
-
Pär Fransman over 11 yearssorry that was find, my misstake.
file libjnidispatch.so
returns: pi@raspberrypi /opt/lib/jna $ file libjnidispatch.so libjnidispatch.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xb2fe121fc0b27c6562e0a73bda21e2bc23193938, not stripped -
technomage over 11 yearsRun with system property
jna.nounpack=true
, which may provide more detail on the library load failure. -
Pär Fransman over 11 yearsI found the problem. JNA.jar was actually missing
libjnidispatch.so
inside thejna.jar
so i just buildjna.jar with Ant
on the Raspberry Pi with openjdk6 and that solved the problem. Its strange though that linking with-Djna.boot.librar.path=/path/to/libjnidispatch.so
still got theUnsatisfiedLinkError
. Oh well, it works now =) Thank you very much for your patiance and input!! -
technomage over 11 yearsjna.boot.library.path (just like LD_LIBRARY_PATH) has to be a path (directories only), not the filename path. glad you got it working.
-
warpech about 11 years@Pär Fransman - do you just use
ant
command inside JNA source downloaded from GitHub? or is there some special config/argument needed? I have the same problem with Processing on Raspberry Pi as you described, but when I compile JNA, it leads to another problem -
warpech about 11 yearsMy error after compiling JNA with ant and copying
jna.jar
to Processing dir is:can't obtain newinstance method for class com.sun jna.structure
. Any ideas? -
technomage about 11 yearsPost full details to the JNA user's list.
-
Chriss over 10 years@PärFransman it would be nice if you could post your own answer, it makes it easier for people like me to find it
-
Ken Ingram almost 5 yearsIt almost worked and what I have discovered is that Elasticsearch 7.1.0 needs libjna-jni at least 5.2.0 andd the latest version for Raspberry Pi is 4.2.2
-
Ken Ingram almost 5 yearsThe solution that worked for me was finding the relevant libjni.*.so library file and adding it to the jna.x.x.ja file.