java.lang.UnsatisfiedLinkError: no XXX in java.library.path

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)

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值