从JAR文件加载库文件 [英] Loading Library files From JAR file

查看:115
本文介绍了从JAR文件加载库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 
线程main中的异常java.lang.UnsatisfiedLinkError:C:\Documents and Settings\dvargo\\ \\ Local Settings\Temp\jmacm.dll:无法在IA 32位平台上加载.dll(机器代码= 0x0)
在java.lang.ClassLoader $ NativeLibrary.load(Native Method)
在java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
在java.lang.ClassLoader.loadLibrary(ClassLoader.java:1699)
在java.lang.Runtime.load0 (Runtime.java:770)
在java.lang.System.load(System.java:1003)
在GlobalUtilities.DllManager.dynamicallyLoadDLL(DllManager.java:160)
在GlobalUtilities。 DllManager.dynamicallyLoadDLLs(DllManager.java:182)
在JMFManager.JMFRunner.dynamicallyLoadJMFDllsFromResource(JMFRunner.java:152)
在JMFManager.JMFRunner.main(JMFRunner.java:164)

 

这是什么意思?



编辑:


$ b $我的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行;
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(异常e)
{
e.printStackTrace();
}
finally
{
try
{
if(br!= null)
{
br.close() ;
}
if(is!= null)
{
is.close();
}

文件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();
}
}
返回null;

}

然后我尝试加载这个dll System.load();并且它会抛出异常。

解决方案

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


I am trying to load a DLL using System.load() in Java. I get this 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)

What does it mean?

EDIT:

I have some dlls in my jar file. I get them out of the jar file and write them to the temp folder with the following code:


    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;

    }

I then try to load this dll with System.load(); and it throws that Exception.

解决方案

Seems like you are trying to load a 64 bit library on a 32bit OS/JVM

这篇关于从JAR文件加载库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆