打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
java.lang.UnsatisfiedLinkError: no XXX in java.library.path
java.lang.UnsatisfiedLinkError: no XXX in java.library.path
2008-09-02 20:35

这几天在linux下弄jni 出了这个错误!查了好多页面才找到答案,现在将原帖位置引用到下面希望能够对和我遇到相同问题的人有所帮助,原帖来自sun网站

http://forums.sun.com/thread.jspa?messageID=4090176

其中涉及的测试源码如下:

For those who didn't install java with default settings, a systematic way for solving JNI class path problem is:
1> include "System.out.println(System.getProperty("java.library.path")); " in your "static" block, right before loading the class.
2> run your program and not surprisingly you got the err again, but this time with java.library.path info for your system. (it's important since this path name varies among systems).
3> cp your libxxx.so into the java.library.path

如果你上面看不懂的话就继续向下面看:
1、 在你载入jni类之前 放入“System.out.println( System.getProperty("java.library.path"));
2、运行你的程序你将获得java.library.path指向的目录
3、拷贝你的libxxx.so到java.library.path指向的某个目录下面。
注意:
      一定要将linux下的共享库(我暂且这么叫:)命名成libxxx.so的形式,"xxx"是你在System.loadLibrary("xxx")中用到的加载库名称。

查了其他的资料:
也可以通过设置LINUX下的系统变量LD_LIBRARY_PATH来添加java.library.path,只要在启动~/.bashrc中添加如下代码然后重新登录shell,就可以将动态库放在当前目录下运行你的jni程序了。
export LD_LIBRARY_PATH=.:..:$LD_LIBRARY_PATH

另外也可以通过如下方法处理该问题
.

I'm new to JNI. I see there are several ways to set JVM to look for libraries dll, so, etc.

System.setProperty("java.library.path", ".");            System.loadLibrary("hello");

That's when UnsatisfiedLinkError
java.lang.UnsatisfiedLinkError: no hello in java.library.path            at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)            at java.lang.Runtime.loadLibrary0(Runtime.java:822)            at java.lang.System.loadLibrary(System.java:992)            at HelloWorld.main(HelloWorld.java:17)

But if I comment the line that sets the java.library.path and call the program with the command java -Djava.library.path=. HelloWorld works.
The question is: Why is not working? How should it be the property setup? I rather don't set Variables, or use -D option.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android之运行Java.lang.UnsatisfiedLinkError的错误解决办法
Calling C code from Java using JNI
Java中System.loadLibrary() 的执行过程
loadLibrary 动态库加载过程分析
jni 加载 so 文件解决方案
Failed to register native method java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad in
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服