在ubuntu中运行JNI程序

时间:2012-07-26 05:22:39

标签: java-native-interface runtime-error

我在ubuntu中运行我的第一个程序。

但是当我尝试运行它时出错:

  Exception in thread "main" java.lang.UnsatisfiedLinkError: no foo in  java.library.path
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
  at java.lang.Runtime.loadLibrary0(Runtime.java:840)
  at java.lang.System.loadLibrary(System.java:1047)
  at JNIFoo.<clinit>(JNIFoo.java:6)
  Could not find the main class: JNIFoo. Program will exit.    

2 个答案:

答案 0 :(得分:2)

这些行取自Getting Stated JNI from SUN site

  

确保本机库位于其中一个目录中   本机库路径。如果您在Solaris系统上运行,则   LD_LIBRARY_PATH环境变量用于定义本机   图书馆路径。确保它包含目录的名称   包含libHelloWorld.so文件。如果是libHelloWorld.so文件   在当前目录中,您可以发出以下两个命令   在标准shell(sh)或KornShell(ksh)中设置   LD_LIBRARY_PATH环境变量正确:

LD_LIBRARY_PATH=.
export LD_LIBRARY_PATH

答案 1 :(得分:1)

Exception in thread "main" java.lang.UnsatisfiedLinkError: no foo in  java.library.path

修复您的库路径,然后重试。