从JAR文件加载库文件

时间:2011-03-18 15:45:50

标签: java exception

我正在尝试使用Java中的System.load()加载DLL。我得到了这个例外:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Documents and Settings\dvargo\Local Settings\Temp\jmacm.dll: Can't load this .dll (machine code=0x0) on a IA 32-bit platform
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1699)
        at java.lang.Runtime.load0(Runtime.java:770)
        at java.lang.System.load(System.java:1003)
        at GlobalUtilities.DllManager.dynamicallyLoadDLL(DllManager.java:160)
        at GlobalUtilities.DllManager.dynamicallyLoadDLLs(DllManager.java:182)
        at JMFManager.JMFRunner.dynamicallyLoadJMFDllsFromResource(JMFRunner.java:152)
        at JMFManager.JMFRunner.main(JMFRunner.java:164)

这是什么意思?

编辑:

我的jar文件中有一些dll。我将它们从jar文件中取出并使用以下代码将它们写入temp文件夹:


    private static ArrayList buf;
    public static InputStream soundStreams;

    public static File getResourceFile(String resourceName, File dest)
    {
        InputStream is = null;
        BufferedReader br = null;
        int line;
        ArrayList list = new ArrayList();

        try
        {
            is = new Object().getClass().getResourceAsStream(resourceName);
            br = new BufferedReader(new InputStreamReader(is));
            while (-1 != (line = br.read()))
            {
                list.add(line);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if (br != null)
                {
                    br.close();
                }
                if (is != null)
                {
                    is.close();
                }

                File newFile = dest;
                newFile.createNewFile();
                FileOutputStream fos = new FileOutputStream(newFile);
                for (Integer i : list)
                {
                    fos.write(i.byteValue());
                }
                fos.close();
                return newFile;
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return null;

    }

然后我尝试使用System.load()加载此dll;并抛出异常。

3 个答案:

答案 0 :(得分:5)

好像你正试图在32位OS / JVM上加载64位库

答案 1 :(得分:2)

UnsatisfiedLinkError是“Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

事实上,例外情况下的第一行是

at java.lang.ClassLoader$NativeLibrary.load(Native Method)

答案 2 :(得分:0)

我在使用Maven项目时遇到了这个问题。 "无法在AMD 64位平台上加载此.dll(机器代码= 0xbd)"

我通过发出以下命令从命令行编译然后按F5刷新项目来禁用Maven性质。

mvn eclipse:clean eclipse:eclipse clean compile test-compile

有关详细信息,请参阅http://sizustech.blogspot.com/2014/12/an-introduction-to-jni-using-bottom-up_70.html