简体   繁体   English

JNA UnsatisfiedLinkError - 当我将java.library.path设置为伪值时起作用

[英]JNA UnsatisfiedLinkError - works when I set java.library.path to a bogus value

Using JNA 4.0.0, on Linux, I am trying to load a native library ( libmean.so ), which is in the lib subdirectory (the library is just a trivial example that calculates the mean of two numbers). 在Linux上使用JNA 4.0.0,我正在尝试加载一个本机库( libmean.so ),它位于lib子目录中(该库只是一个计算两个数字平均值的简单示例)。

I run the following code (within Eclipse), with -Djna.library.path=lib set in the run configuration. 我运行以下代码(在Eclipse中),在运行配置中设置了-Djna.library.path=lib

import com.sun.jna.Library;
import com.sun.jna.Native;

public class Mean {
  public interface MeanLib extends Library {    
    MeanLib INSTANCE = (MeanLib) Native.loadLibrary("mean", MeanLib.class);
    double mean(double a, double b);
  }
  public static void main(String[] args) {          
    double result = MeanLib.INSTANCE.mean(1.0, 3.0);
    System.out.println(result);
  }
}

But this fails with the following exception: 但是这失败了以下例外:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't obtain updateLastError method for class com.sun.jna.Native
at com.sun.jna.Native.initIDs(Native Method)
at com.sun.jna.Native.<clinit>(Native.java:139)
at com.sun.jna.examples.Mean$MeanLib.<clinit>(Mean.java:64)
at com.sun.jna.examples.Mean.main(Mean.java:72)

Through trial-and-error, I have discovered that the code starts working if I also set java.library.path . 通过反复试验,我发现如果我也设置了java.library.path ,代码就会开始工作。

However, it works regardless of the value of this property. 但是,无论此属性的值如何,它都可以工作。 For example, I can set -Djava.library.path=xxxxxxx and it continues to work. 例如,我可以设置-Djava.library.path=xxxxxxx并继续工作。 An empty value also works. 空值也有效。

What is going on? 到底是怎么回事?

The root problem is that there is an older version of JNA installed on the system: 根本问题是系统上安装了旧版本的JNA:

$ dpkg -l | grep -i jna
ii  libjna-java  3.2.7-4 Dynamic access of native libraries from Java without JNI

JNA starts up by trying to load its bootstrap native library. JNA通过尝试加载其引导本机库来启动。 It searches for this in various places, as described in the documentation . 它在各个地方搜索它,如文档中所述。

The problem is fixed by using the -Djna.nosys=true flag, which forces JNA to load the native library from your jna.jar , not from the system. 通过使用-Djna.nosys=true标志来解决此问题,该标志强制JNA从jna.jar加载本机库,而不是从系统加载。

Setting the java.library.path to a nonsense value has a similar side-effect - it overwrites the normal java.library.path , preventing the system version of JNA from being loaded, and falling back on the version from your local jna.jar . java.library.path设置为无意义的值具有类似的副作用 - 它会覆盖正常的java.library.path ,从而阻止加载JNA的系统版本,并从本地jna.jar返回版本。

The debug setting -Djna.debug_load=true is also useful for diagnosing JNA problems. 调试设置-Djna.debug_load=true对于诊断JNA问题也很有用。

$ dpkg -l | grep -i jna

try this command and if u getting this output 尝试此命令,如果你得到这个输出

ii  libjna-java  3.2.7-4 Dynamic access of native libraries from Java without JNI

or any other output then this u need to remove then that jna from the system because if program itself have jna jar with that then there is no need of system jna for the same. 或者任何其他输出然后你需要从系统中删除那个jna,因为如果程序本身有jna jar,那么就不需要系统jna了。 so do something like this. 做这样的事情。

sudo apt-get autoremove libjna-java

and try for restart that application again. 并尝试再次重新启动该应用程序。 it will run and it is not running then try to install new version of libwebkit-gtk . 它将运行并且它没有运行然后尝试安装新版本的libwebkit-gtk

hope this will help. 希望这会有所帮助。 this helped me. 这对我有帮助。

I got this error when I'd installed Netbeans 7 via apt-get which pulled in libjna-java (3.2.7-4). 当我通过apt-get安装了Netbeans 7时出现了这个错误,这是在libjna-java(3.2.7-4)中引入的。

Since Netbeans 7 is old, I installed version 8 via their shell installer after removing the debian packages. 由于Netbeans 7已经过时,我在删除debian软件包后通过shell安装程序安装了版本8。 Be sure and autoremove to get rid of libjna. 一定要自动去除libjna。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我为什么会收到“ UnsatisfiedLinkError:java.library.path中没有SolarisSerialParallel” - Why am I getting “UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path” 获取UnsatisfiedLinkError:创建TessBaseAPI时java.library.path中没有jnilept - Getting UnsatisfiedLinkError: no jnilept in java.library.path when I create TessBaseAPI UnsatisfiedLinkError java.library.path中没有慢跑 - UnsatisfiedLinkError no jogl in java.library.path UnsatisfiedLinkError:java.library.path中没有jcprov - UnsatisfiedLinkError: no jcprov in java.library.path UnsatisfiedLinkError:java.library.path中没有nlsxbe - UnsatisfiedLinkError: no nlsxbe in java.library.path UnsatisfiedLinkError:java.library.path中没有libhello - UnsatisfiedLinkError: no libhello in java.library.path java.lang.UnsatisfiedLinkError:否 <LIBRARY> 在java.library.path中 - java.lang.UnsatisfiedLinkError: no <LIBRARY> in java.library.path java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl,但是设置了本机 - java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path but natives are set 在 ubuntu 上使用 JNI 时出错:java.lang.UnsatisfiedLinkError: no ... in java.library.path - Error when using JNI on ubuntu: java.lang.UnsatisfiedLinkError: no … in java.library.path java.lang.UnsatisfiedLinkError:cqjnilinuxproxy(在java.library.path中找不到) - java.lang.UnsatisfiedLinkError: cqjnilinuxproxy (Not found in java.library.path)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM