Mathematica、J/LINK、JNI、.dll
我正在尝试通过 Mathematica 的 J/Link 获取 Java 方法。问题在于该方法调用 JNI(.dll 文件)。在 Mathematica 之外的命令行中,一切都运行良好。但是在 Mathematica 中调用该方法时,JVM 返回以下内容:
Java::excptn: A Java exception occurred: java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5Fcreate(Ljava/lang/String;III)I
at ncsa.hdf.hdf5lib.H5.H5Fcreate(Native Method)
at ncsa.hdf.object.h5.H5File.createFile(H5File.java:920)
at H5FileCreateFromMathematica.H5FileCreate(H5FileCreateFromMathematica.java:38).
我花了很多时间尝试使类路径和路径在各种排列中都正确。这可能仍然是问题所在,尽管我觉得我已经努力排除这些可能性。
如果您能深入了解 (1) 来自 Java 的这条消息的含义,甚至更好 (2) 如何修复它,我们将不胜感激。
- 编辑:更多信息,在实施 Artefacto 非常有用的建议之后* Artefacto 输入的结果是错误消息的更改。第一次调用时, fileFormat@create["C:\Test"] 产生:
Java::excptn: 发生 Java 异常:java.lang.UnsatisfiedLinkError: Native Library C:\MyJava\hdf-java\lib\win \jhdf5.dll 已加载到另一个类加载器中 在 java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1772) 在 java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732) 在 java.lang.Runtime.loadLibrary0(Runtime.java:823) 在 java.lang.System.loadLibrary(System.java:1028) 在 ncsa.hdf.hdf5lib.H5.
立即再次调用,fileFormat@create["C:\Test"] 产生:
Java::excptn: A Java 异常发生:java.lang.NoClassDefFoundError:无法初始化类 ncsa.hdf.hdf5lib.H5 在 ncsa.hdf.object.h5.H5File.createFile(H5File.java:920) at ncsa.hdf.object.FileFormat.create(FileFormat.java:1472)。
对于解释这些更改以及使其在 Mathematica 中工作可能意味着什么有任何帮助吗?
I am trying to get a Java method to work via J/Link from Mathematica. The problem is that the method calls a JNI (.dll file). Outside of Mathematica from the command line, all works great. But calling the method within Mathematica, the JVM returns the following:
Java::excptn: A Java exception occurred: java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5Fcreate(Ljava/lang/String;III)I
at ncsa.hdf.hdf5lib.H5.H5Fcreate(Native Method)
at ncsa.hdf.object.h5.H5File.createFile(H5File.java:920)
at H5FileCreateFromMathematica.H5FileCreate(H5FileCreateFromMathematica.java:38).
I have spent a lot of time trying to get everything right with classpath and path in various permutations. This might still be the problem, though I feel I have worked hard to rule out these possibilities.
Any insights onto (1) what this message from Java means and even better (2) how to fix it would be much appreciated.
- EDIT: FURTHER INFORMATION, after implemeneting Artefacto's very helpful suggestion *
The result of Artefacto's input is a change in the error message. On first call, fileFormat@create["C:\Test"] yields:
Java::excptn: A Java exception occurred: java.lang.UnsatisfiedLinkError: Native Library C:\MyJava\hdf-java\lib\win\jhdf5.dll already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1772)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at ncsa.hdf.hdf5lib.H5.<clinit>(H5.java:232)
at ncsa.hdf.object.h5.H5File.createFile(H5File.java:920)
at ncsa.hdf.object.FileFormat.create(FileFormat.java:1472).
Calling immediately again, fileFormat@create["C:\Test"] yields:
Java::excptn: A Java exception occurred: java.lang.NoClassDefFoundError: Could not initialize class ncsa.hdf.hdf5lib.H5
at ncsa.hdf.object.h5.H5File.createFile(H5File.java:920)
at ncsa.hdf.object.FileFormat.create(FileFormat.java:1472).
Any help in the interpretation of these changes and what it might mean for getting this to work in Mathematica?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 正在寻找本机库,但没有找到。根据下面链接的论坛帖子,您应该设置“com.wolfram.jlink.libdir”系统属性或 JLINK_LIB_DIR 环境变量。这可能会配置它应该在哪里查找 JLink 本身,因此您也可以尝试将所需的库放置在 Mathematica 安装布局中 JLinkNativeLibrary.dll 文件所在的位置。
这是相关的论坛主题:
http://forums.wolfram.com/mathgroup/archive/2008/Aug /msg00664.html
Java is looking for the native library but not finding it. According to the forum post linked below, you should set the "com.wolfram.jlink.libdir" system property or the JLINK_LIB_DIR environment variable. This may be configuring where it should look for JLink itself so you might also try to put the required library where the JLinkNativeLibrary.dll file lives in the Mathematica installation layout.
This is the related forum thread:
http://forums.wolfram.com/mathgroup/archive/2008/Aug/msg00664.html
尝试在命令行中传递 JVM dll 目录的路径,如下所示:
然后调用 Runtime.getRuntime().loadLibrary("mylib");:
Try passing the JVM, in the command line, the path of the dll directory, like so:
Then call
Runtime.getRuntime().loadLibrary("mylib");
: