2

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?

0

2 Answers 2

2

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

1
  • Thanks, Joshua, for the link over to MathGroup. The problem cropping up for me is different from that one. That is, the error message about the JLinkNativeLibrary (Mathgroup discussion) relates to the booting up JLink as part of the standard Mathematica-Java communication. That part is fine for me. My problem is related to getting the JVM to find the native library of my application. For anyone who wants to follow this thread further, I am going to post more information here: java-forums.org/advanced-java/…
    – user815784
    Jun 26, 2011 at 20:42
2

Try passing the JVM, in the command line, the path of the dll directory, like so:

InstallJava[CommandLine-> "c:\\path\\to\\java.exe -Djava.library.path=c:\\path\\to\\libdirectory"]

Then call Runtime.getRuntime().loadLibrary("mylib");:

LoadJavaClass["java.lang.Runtime"];
runtime = java`lang`Runtime`getRuntime[];
process = runtime@loadLibrary["mylib"];
1
  • Very helpful reply, and I gave it a try. I especially appreciate that you could put this into Mathematica format (!). See effects in original message above.
    – user815784
    Jun 26, 2011 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.