无法从 class com.sun.jna.Native 获取静态方法 fromNative(Method, Object)
Can't obtain static method fromNative(Method, Object) from class com.sun.jna.Native
我正在使用 JNA 的 com.sun.jna.NativeLibrary
class 来加载 VLCJ
本机库。我正在研究 armv8(aarch x64)-based linux device
。下面是我的代码,注意我使用的是最新的 JNA 版本 jna-4.5.2
:
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), Constants.DEPLIB_OUTPUT_DIRECTORY);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
LibXUtil.initialise();
首先我收到这个错误:
java.lang.UnsatisfiedLinkError: JNA native support (com/sun/jna/linux-aarch64/libjnidispatch.so) not found in resource path
快速搜索后,我发现我必须将 jar 内的 jna 本机 lib 目录复制到 jvm lib 路径,其中 jna jar 库为几乎所有已知系统预构建库,如图所示以下:
jna-4.5.2 internal content.jpeg
之后,上面的异常消失了,但又出现了一个:
java.lang.UnsatisfiedLinkError: Can't obtain static method fromNative(Method, Object) from class com.sun.jna.Native
异常是说在 class com.sun.jna.Native 中找不到方法 fromNative(Method, Object) 但是在反编译后 class 我发现这个方法已经存在了。
我不知道,任何帮助将不胜感激,谢谢!
解决方法:
- 撤消此步骤:
After a quick search i found that i must copy the jna
native lib
directory from inside the jar into the jvm
lib path...
- 从我的项目中删除所有
jna
个模块(jar)
- 下载并link以下 jar 到我的项目中:
jna.jar
jna-platform.jar
linux-aarch64.jar
如果 jar 文件:jna-5.11.0.jar 和 jna-platform-5.11.0.jar(或您使用的任何版本号)如果在您的 lib 路径(构建路径在 Eclipse 中),java 命令选项:
-Djna.nosys=true
可能会解决问题。第一次启动时,JNA 会加载它自己的本机访问库,但找不到它。 jna.nosys=true 允许 JNA 在 jna-X.XX.X.jar 文件中查找它需要的内容。错误消息让我感到困惑,因为 JNA 似乎已找到并加载,但它抱怨找不到 'fromNative'.
Loading JNA
JNA includes a small, platform-specific shared library which enables all
native access. When the Native class is first accessed, JNA will first
attempt to load this library from the directories specified in
jna.boot.library.path. If that fails and jna.nosys=false is set, it will
fall back to loading from the system library paths. Finally it will attempt
to extract the stub library from from the JNA jar file, and load it.
The jna.boot.library.path property is mainly to support jna.jar being
included in -Xbootclasspath, where java.library.path and LD_LIBRARY_PATH are
ignored. It is also useful for designating a version of the library to use
in preference to any which may already be installed on the system.
...
我正在使用 JNA 的 com.sun.jna.NativeLibrary
class 来加载 VLCJ
本机库。我正在研究 armv8(aarch x64)-based linux device
。下面是我的代码,注意我使用的是最新的 JNA 版本 jna-4.5.2
:
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), Constants.DEPLIB_OUTPUT_DIRECTORY);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
LibXUtil.initialise();
首先我收到这个错误:
java.lang.UnsatisfiedLinkError: JNA native support (com/sun/jna/linux-aarch64/libjnidispatch.so) not found in resource path
快速搜索后,我发现我必须将 jar 内的 jna 本机 lib 目录复制到 jvm lib 路径,其中 jna jar 库为几乎所有已知系统预构建库,如图所示以下:
jna-4.5.2 internal content.jpeg
之后,上面的异常消失了,但又出现了一个:
java.lang.UnsatisfiedLinkError: Can't obtain static method fromNative(Method, Object) from class com.sun.jna.Native
异常是说在 class com.sun.jna.Native 中找不到方法 fromNative(Method, Object) 但是在反编译后 class 我发现这个方法已经存在了。
我不知道,任何帮助将不胜感激,谢谢!
解决方法:
- 撤消此步骤:
After a quick search i found that i must copy the
jna
native lib directory from inside the jar into thejvm
lib path...
- 从我的项目中删除所有
jna
个模块(jar) - 下载并link以下 jar 到我的项目中:
jna.jar
jna-platform.jar
linux-aarch64.jar
如果 jar 文件:jna-5.11.0.jar 和 jna-platform-5.11.0.jar(或您使用的任何版本号)如果在您的 lib 路径(构建路径在 Eclipse 中),java 命令选项:
-Djna.nosys=true
可能会解决问题。第一次启动时,JNA 会加载它自己的本机访问库,但找不到它。 jna.nosys=true 允许 JNA 在 jna-X.XX.X.jar 文件中查找它需要的内容。错误消息让我感到困惑,因为 JNA 似乎已找到并加载,但它抱怨找不到 'fromNative'.
Loading JNA JNA includes a small, platform-specific shared library which enables all native access. When the Native class is first accessed, JNA will first attempt to load this library from the directories specified in jna.boot.library.path. If that fails and jna.nosys=false is set, it will fall back to loading from the system library paths. Finally it will attempt to extract the stub library from from the JNA jar file, and load it. The jna.boot.library.path property is mainly to support jna.jar being included in -Xbootclasspath, where java.library.path and LD_LIBRARY_PATH are ignored. It is also useful for designating a version of the library to use in preference to any which may already be installed on the system. ...