Managing native method libraries
To use native method libraries, especially when you want to manage multiple versions of a native method library on your IBM® i server, you need to understand both the Java™ library naming conventions and the library search algorithm.
The Java method System.loadLibrary() is used to load a native library given a library name. IBM i uses the first native method library that matches the name of the library that the Java virtual machine (JVM) loads. In order to ensure that IBM i finds the correct native methods, you must avoid library name clashes and confusion about which native method library the JVM uses.
Native library naming conventions
- If the native methods are ILE native methods and the Java code loads a library named Sample, the corresponding executable file must be an ILE service program named SAMPLE.
- If the native methods are PASE for i native methods and the Java code loads a library named Sample, the corresponding executable file must be an AIX library named either libSample.a or libSample.so.
Java library search order
To locate a native library, Java uses the java.library.path property to determine the search path. By default, the java.library.path property is set to a value that is a result of the concatenation of two lists (in the following order):
- IBM i library list
- The value of the LIBPATH environment variable
In order to perform the search, IBM i converts the library list to the integrated file system format. QSYS file system objects have equivalent names in the integrated file system, but some integrated file system objects do not have equivalent QSYS file system names. Because the library loader looks for objects in both the QSYS file system and in the integrated file system, IBM i uses the integrated file system format to search for native method libraries.
The following table shows how IBM i converts entries in the library list to the integrated file system format:
Library list entry | Integrated file system format |
---|---|
QSYS | /qsys.lib |
QSYS2 | /qsys.lib/qsys2.lib |
QGPL | /qsys.lib/qgpl.lib |
QTEMP | /qsys.lib/qtemp.lib |
Example: Searching for the Sample2 library
In this example, the LIBPATH environment variable is set to /home/user1/lib32:/samples/lib32. The following table, when read from top to bottom, indicates the full search path:
Source | Integrated file system directories |
---|---|
Library list |
|
LIBPATH |
|
In order to search for library Sample2, the Java library loader searches for file candidates in the following order:
- /qsys.lib/sample2.srvpgm
- /qsys.lib/libSample2.a
- /qsys.lib/libSample2.so
- /qsys.lib/qsys2.lib/sample2.srvpgm
- /qsys.lib/qsys2.lib/libSample2.a
- /qsys.lib/qsys2.lib/libSample2.so
- /qsys.lib/qgpl.lib/sample2.srvpgm
- /qsys.lib/qgpl.lib/libSample2.a
- /qsys.lib/qgpl.lib/libSample2.so
- /qsys.lib/qtemp.lib/sample2.srvpgm
- /qsys.lib/qtemp.lib/libSample2.a
- /qsys.lib/qtemp.lib/libSample2.so
- /home/user1/lib32/sample2.srvpgm
- /home/user1/lib32/libSample2.a
- /home/user1/lib32/libSample2.so
- /samples/lib32/sample2.srvpgm
- /samples/lib32/libSample2.a
- /samples/lib32/libSample2.so