Haj Haj - 1 year ago 57
Java Question

While loading JNI library, how the mapping happens with the actual library name

We load any native library by using


Now I came to know that this library name refers to hello.dll for windows
and libhello.so for unix based system.

So where these platform dependent changes happens?

Is JRE doing this?

Answer Source

Short answer: yes.

From the Javadoc for loadLibrary: "Loads the system library specified by the libname argument. The manner in which a library name is mapped to the actual system library is system dependent." System.mapLibraryName(libname) will return what the mapped library name will be.

This reflects the common conventions for library names: lib prefix in Linux and Mac OS X, no prefix in Windows, plus platform dependent file extension. Note that the extension for JNI libraries on Mac OS X is jnilib, not dylib as it is for other libraries. Also this mapping is not unique to the Java runtime, gcc ... -lhello will also look for libhello.so (or libhello.dylib on Mac OS X).

If you don't want the runtime to do this mapping, you'd have to determine the correct filename including the extension yourself and pass this to loadLibrary

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download