java - 从 JAR 文件加载库文件

标签 java exception

<分区>

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

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 文件中取出并使用以下代码将它们写入临时文件夹:


    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;并抛出该异常。

最佳答案

似乎您正在尝试在 32 位操作系统/JVM 上加载 64 位库

关于java - 从 JAR 文件加载库文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5354442/

相关文章:

java - 唯一数字数组

ruby - 这个救援示例有什么问题?

python - 为什么这个迭代的列表增长代码会给出 IndexError : list assignment index out of range? 如何将元素重复添加(附加)到列表中?

java - 在应用程序层之间传输 Java 异常堆栈跟踪

windows-phone-7 - 缺少 ApplicationException 基类?

java - 避免 Iterator ConcurrentModificationException 的方法

Java 规范实现 - 从那里获取正在实现的接口(interface)的导入

java - 以编程方式下载通过 PHP 页面推送的文件

java - Java中如何重写equals方法

php - 处理 php 中的特定异常