tags:

views:

1148

answers:

1

I'm using a JAR file of my own, which uses a Java library (JHDF5), that in turn uses a dll through JNI. When I use my own JAR file in MATLAB, and then have to rebuild it while debugging, I get this error when I try to use it again, after calling clear java and creating a new object from my JAR file:

java.lang.UnsatisfiedLinkError: 
Native Library C:\deka\proj\java\ESPDF\dist\lib\jhdf5.dll 
already loaded in another classloader

and I can't solve it without shutting down MATLAB and reopening, which is a pain in the neck.

What is this error and whose fault is it? (mine? MATLAB's? JHDF5 for not freeing the DLL or checking to see if it's already loaded)

+4  A: 

In general, there is no way for Java code to unload a native dll. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5075039

Given that, once a dll is loaded, it's there for the lifetime of the JVM and the VM will ensure that it is loaded once and only once.

To answer the question of blame, I suppose it's the fault of the code that attempts to load the dll without checking if its already available.

gibbss
re: blame: good, because it's a lot easier for me to hope to change HDF5 (or at least rebuild it myself) than Matlab.
Jason S
It's probably not Matlab loading it, or I think you'd get the error the first time instead of only after the rebuild. You can use the undocumented "feature dumpmem" Matlab command to get a list of DLLs Matlab has loaded.
Andrew Janke