I have a Glassfish 3.1.1 web application for Java EE 6 running. one of my classes has a native library dependency. I'm using JNI to use this native method. Part of that process involves creating a shared library .so file. In one of my Java classes there will be a System.Loadlibrary("library"); call that references that library.so file.
My questions is, where should I place this shared library as well as the native code that it references in order to access and use this JNI functionality on Glassfish.
I'll need to make calls to several C++ programs that can be moved anywhere on the machine that that Glassfish is hosted on. Should I put them in the domain1/ext folder? add them as a native library to a jar in the build path. How is this done?
Use the following Glassfish command to set the path where your native libraries are located:
It is also possible to set the native library location via the Admin Console. If you want flexibility in moving/renaming the libraries, you can use symbolic links.
The JVM needs to know the native library path. If you launch the JVM from Eclipse (e.g. unit testing with the native library), then you will need to configure the path in Eclipse. However, if you launch the JVM from Glassfish (by using the Eclipse Glassfish Adapter) then Glassfish itself needs to be configured.