recipe № 018

dynamic loading of library in JNI

Sometimes, you want to change native code while JVM is running. In Java, it is not easy to reload native library. However, you can always make a trick by loading it in a wrapper library. In this scenario, what you do is loading native library each time you want to call native code.

recipeno018

There is one step that is important here. You have to make sure to load and call the code from shared library that you want to use

What are the possible cases where you can use this approach?

– you want to change native code while Java application is running
– you want to switch between native implementations that are called from Java (debug/release)
– you want to simulate reloading shared library in Java (note that reloading JNI code in Java is quite cumbersome)