Managing native method libraries

To use native method libraries, especially when you want to manage multiple versions of a native method library on your iSeries™ server, you need to understand both the Java™ library naming conventions and the library search algorithm.

i5/OS™ 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 i5/OS finds the correct native methods, you must avoid library name clashes and confusion about which native method library the JVM uses.

i5/OS PASE and AIX® Java Library Naming Conventions

If the Java code loads a library named Sample, the corresponding executable file must be named either libSample.a or libSample.so.

Java library search order

When you enable i5/OS PASE native methods for the JVM, your server uses three different lists (in the following order) to create a single native method library search path:

  1. i5/OS library list
  2. LIBPATH environment variable
  3. PASE_LIBPATH environment variable

In order to perform the search, i5/OS 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, i5/OS uses the integrated file system format to search for native method libraries.

The following table shows how i5/OS 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 the following example, LIBPATH is set to /home/user1/lib32:/samples/lib32 and PASE_LIBPATH is set to /QOpenSys/samples/lib.

The following table, when read from top to bottom, indicates the full search path:

Source Integrated file system directories
Library list

/qsys.lib
/qsys.lib/qsys2.lib
/qsys.lib/qgpl.lib
/qsys.lib/qtemp.lib

LIBPATH

/home/user1/lib32
/samples/lib32

PASE_LIBPATH /QOpenSys/samples/lib
Note: Uppercase and lowercase characters are significant only in the /QOpenSys path.

In order to search for library Sample2, the Java library loader searches for file candidates in the following order:

  1. /qsys.lib/sample2.srvpgm
  2. /qsys.lib/libSample2.a
  3. /qsys.lib/libSample2.so
  4. /qsys.lib/qsys2.lib/sample2.srvpgm
  5. /qsys.lib/qsys2.lib/libSample2.a
  6. /qsys.lib/qsys2.lib/libSample2.so
  7. /qsys.lib/qgpl.lib/sample2.srvpgm
  8. /qsys.lib/qgpl.lib/libSample2.a
  9. /qsys.lib/qgpl.lib/libSample2.so
  10. /qsys.lib/qtemp.lib/sample2.srvpgm
  11. /qsys.lib/qtemp.lib/libSample2.a
  12. /qsys.lib/qtemp.lib/libSample2.so
  13. /home/user1/lib32/sample2.srvpgm
  14. /home/user1/lib32/libSample2.a
  15. /home/user1/lib32/libSample2.so
  16. /samples/lib32/sample2.srvpgm
  17. /samples/lib32/libSample2.a
  18. /samples/lib32/libSample2.so
  19. /QOpenSys/samples/lib/SAMPLE2.srvpgm
  20. /QOpenSys/samples/lib/libSample2.a
  21. /QOpenSys/samples/lib/libSample2.so

i5/OS loads the first candidate in the list that actually exists into the JVM as a native method library. Even though candidates like '/qsys.lib/libSample2.a' and '/qsys.lib/libSample2.so' occur in the search, it is not possible to create integrated file system files or symbolic links in the /qsys.lib directories. Therefore, even though i5/OS checks for these candidate files, it will never find them in integrated file system directories that begin with /qsys.lib.

However, you can create arbitrary symbolic links from other integrated file system directories to i5/OS objects in the QSYS file system. As a result, valid file candidates include files such as /home/user1/lib32/sample2.srvpgm.

Related concepts
Java i5/OS PASE environment variables
Java i5/OS PASE error codes
Example: IBM i5/OS PASE native method for Java