System.loadLibrary() - Loading DLL for JNI Interface

Q

An application needs to load a library before it starts to run, how to code?

✍: FYIcenter

A

One option is to use a static block to load a library before anything is called. For example,

class Test {
   static {
       System.loadLibrary("myApp.dll");
   }
   ....
}

When you call new Test(), the static block will be called first before any initialization happens. Note that the static block position may matter.

2007-03-03, 8010👍, 0💬