日期:2014-05-20  浏览次数:20940 次

求助!用eclipse编写JNI程序出现UnsatisfiledLinkError异常
这两天在学习JNI。用家里的电脑在eclipse上编写没有出问题。但是换了台电脑就出问题了。。最简单的Jni HelloWorld编译不通过。以下是java部分的代码:

package jni;
 
public class HelloWorld {
    static{
        System.loadLibrary("helloworld");
    }
 
    public native void dispHelloWorld();
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODOAuto-generated method stub
        //System.getProperty("java.library.path");
        new HelloWorld().dispHelloWorld();
    }
 
}


按照网上查到的JNI编写步骤进行,在第一步就出问题了。最开始编译这个java文件就不能通过。正常情况应该是编译通过以后用编译得到的class文件生成.h文件吧。
出现异常:
Thread[main](Suspended(exception UnsatisfiledLinkError))
  ClassLoader.loadLibrary(Class, String, boolean) line: not available
  Runtime.loadLibrary0(Class, String) line: not available
  System.loadLibrary(String) line: not available
  HelloWorld.<clinit>() line: 5
我试了一下用cmd执行javac命令可以编译通过。可是用eclipse就老出问题。求大神解答!!我已经被这个问题折磨很久了。。非常感谢。
Eclipse JNI Java

------解决方案--------------------
这是源代码
// Invoked in the java.lang.Runtime class to implement load and loadLibrary.
    static void loadLibrary(Class fromClass, String name,
    boolean isAbsolute) {
        try {
            if (!DownloadManager.isJREComplete() && 
                    !DownloadManager.isCurrentThreadDownloading()) {
                DownloadManager.downloadFile("bin/" + 
                    System.mapLibraryName(name));
                // it doesn't matter if the downloadFile call returns false --
                // it probably just means that this is a user library, as 
                // opposed to a JRE library
            }
        } catch (IOException e) {