Question

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?

Was it helpful?

Solution

Use the following Glassfish command to set the path where your native libraries are located:

asadmin set server.java-config.native-library-path-prefix=$NATIVE_LIBRARY_PATH

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.

What is the advantage of this to adding a native library through Eclipse build path?

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.

OTHER TIPS

When I Use a JNI Wrapped DLL in Windows Based server, Have Place the DLL in

    C:/Windows/System32

You can try placing .so on linux machine at

   /usr/lib64/

just a try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top