Search code examples
javamatlabdlljava-native-interface

Java JNI, multiple versions of a dll: How to specify which dll is being used for native calls (matlab jvm)


I am facing a special situation. I am trying to run a java application within matlab. My application uses an external dll which depends on another dll (xerces-c_3_2.dll). My problem is that matlab also contains a xerces-c_3_2.dll in its root folder.

Unfortunately, these two dll files are different! It is not possible to change the library path of the jvm within matlab in a way, that the 'matlab'-version of the dll is not shadowing my dll version (it's automatically loaded on matlab startup). Due to this, my application is always throwing exceptions that a procedure could not be found because its using the wrong version.

Since matlab won't start with my version of the dll, my idea is now to rename the dll to 'xerces-c_3_2_myVersion.dll' and load it redundantly.

How can I tell the jvm for a specific jni call which native interface should be used?

In my jni interface the known public final static native lines are defined, but I never faced the question how to specify the dll in case of redundant native functions?

Any ideas? Thank you! Sven


Solution

  • I have resolved my problem:

    1. I renamed my version of the dll file from 'xerces-c_3_2.dll' to 'xerces-c_3_s.dll'
    2. I modified my compiled personal dll in a hex editor and changed the dependency acc. to the naming in (1)
    3. I loaded the modified dll with the changed dependency using java within matlab. Now it's working without any problems!

    So technically it was more a windows library thing rather than a java question.