【问题标题】:Loading Library files From JAR file [duplicate]从 JAR 文件加载库文件 [重复]
【发布时间】:2011-07-18 06:54:22
【问题描述】:

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

线程“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 在 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)

什么意思?

编辑:

我的 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 位 JVM?
  • 您正在尝试做的事情看起来几乎与stackoverflow.com/questions/1611357/…中接受的答案完全相同
  • @dcn 很酷,让我试试看效果如何

标签: java exception


【解决方案1】:

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

【讨论】:

  • 嗯,我不想假设任何关于 OP 试图加载的库,但这可能是真的。 +1
  • 这是有趣的部分。我在 XP 上。如果我将 dll 放在 win32 文件夹中,它会正确加载,但是,如果我尝试从我指定的文件夹中动态加载它,则会出现此异常。
  • 你使用的是什么库?
  • 它们是 JMF 使用的 dll。 JMF 安装程序将它们放在 Win32 文件夹中。我希望能够在任何地方使用它们。
【解决方案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)

【讨论】:

  • ...您的编辑不包含问题。为什么要把题目从一个问题改成一个句子片段?
  • 不,我的编辑不包含问题,但它确实提供了有关我正在做什么可能导致异常的更多信息。我改变了标题,因为我希望人们真正看到这篇文章,我会通过使用一个有趣的标题来获得更多的浏览量。如果我看到这个标题,我会更倾向于查看它。
【解决方案3】:

我在使用 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 了解更多信息。

【讨论】:

    猜你喜欢
    • 2013-08-26
    • 2018-12-31
    • 2013-06-15
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 2019-01-02
    • 2014-05-07
    • 2012-09-11
    相关资源
    最近更新 更多