Where to host the .so shared library for regular JNI calls when deployed in a Java EE Glassfish application

I have a Glassfish 3.1.1 web application to run Java EE 6. one of my classes has a native library dependency. I use JNI to use this native method. Part of this process includes creating a .so file. Shared library. In one of my Java classes, System.Loadlibrary ("library") will be created; a call that references the library.so file.

My questions are: where should I put this shared library, as well as the native code that it references in order to access and use this JNI functionality in Glassfish.

I will need to make calls to several C ++ programs that can be moved anywhere on the machine that hosts Glassfish. Should I put them in the domain1 / ext folder? add them as a native library to the jar in the build path. How it's done?

+4
source share
2 answers

Use the following Glassfish command to indicate the path where your own libraries are located:

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

You can also set the location of your own library through the admin console. If you need the flexibility of moving / renaming libraries, you can use symbolic links.

What is the advantage of this in adding your own library through Eclipse to build a path?

The JVM must know the path of its own library. If you run the JVM from Eclipse (for example, testing a module using its own library), you will need to configure the path in Eclipse. However, if you run the JVM from Glassfish (using the Eclipse Glassfish Adapter), then Glassfish itself must be configured.

+8
source

When I use the JNI Wrapped DLL on a Windows server, put the DLL in

  C:/Windows/System32 

You can try placing .so on a linux machine in

  /usr/lib64/ 

try it.

-2
source

Source: https://habr.com/ru/post/1392125/


All Articles