开发者

Checking a loadable JNI Library

I have a question. Is there a way by which I can check if a dll can be loaded without actually loading it? My problem is as follows:

I am using a Third party API that needs to load a native library. But the weird thing is that despite being a "Library" it will make a call to System.exit() if it cannot load the native library. Although my application depends on that library, I do not want my application to crash even if I cannot use the library which is only a feature in my application [albeit an important one]. So before I use the library, I want to check if the dll is lo开发者_运维百科adable. I tried to do this by making an check if an UnsatisfiedLinkError was thrown from the statement System.loadLibrary("LibraryName"). If an error was thrown then I do not use that library. However If it does not throw any error I go with using the library. Now after doing this I get the following error:

Cannot native library. The libary was already loaded in a different ClassLoader.

Hance I cannot load the library from the System.loadLibrary() method and do it only from the Third Party library. So, my question is "How can I check if a library is loadable without actually loading it?"


If a library cannot be loaded, it shouldn't call system.exit(). When ever I attempt to load a library whichc annot be loaded, I get an error. Is it possible that your library which is not loading correctly is killing the process. The only way to check for this is to have a seperate process attempt to load the library and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜