Guidelines


Using Java Native Interface (JNI) on NetWare

The java\bin directory includes a file named jni.zip. When you extract this file, it demonstrates simple native method examples for Java 1.x. This section is an example of how to write native methods for NJVM. It is not a comprehensive tutorial on writing native methods.


Required Tools


File Descriptions

File Description

MAKEFILE

Make file for NetWare

NWNATIVE.JAVA

Native method Java class

NWTEST.JAVA

Test class

README.TXT

 

NWIMPL.C

Native method C implementation

NWMAIN.C

CLIB NLMTM wrapper - main()


Building a JNI Example

After you unpack the package, complete the following:

  1. Configure the following parameters in Makefile:

    WIN32JAVABASE - Specify where the Win32 JDK is installed.

    NWJAVABASE - Specify where the NetWare JDK is installed (typically the mounted SYS: drive).

    NLMSDKBASE - Specify where the NetWare NDK is installed.

    WATCOMBASE - Specify where Watcom 11.0 is installed.

  2. Enter the following at a Windows command prompt:

    nmake

    The following are the file descriptions:

  3. To clean the build, enter the following at a Windows command prompt:

    nmake clean


Installing a JNI Example

After you build the example and map your server volume sys: to drive G:, complete the following steps to install JNI:

  1. Check to see if G:\java\classes exists as a directory. If not, enter

    mkdir G:\java\classes

  2. Copy the NLM to G:\java\bin by entering:

    copy nwnative.nlm G:\java\bin

  3. Copy the classes to G:\java\classes, then at the command prompt in Windows enter:

    copy *.class g:\java\classes


Running a JNI Example

If your CLASSPATH variable is correct, you can run JNI by entering the following at the command prompt:

java NWTest


Unloading JNI

To unload JNI, at the Server Console enter

java -exit


JNI Notes

This section contains notes and examples that might be helpful with the JNI process:

  1. What you can do in your main() function depends on how you build your NetWare Loadable ModuleTM (NLM) program. If you include the following option in your Makefile, your NLM program can use a synchronized startup:

    Option SYNCHRONIZE

    With the synchronize option, you can initialize any global information your NLM program might contain in the main() function as long as you call the following function after initialization has completed:

    void SynchronizeStart();

    For example:

    main()

    {

    /* Do global initialization */

    SynchronizeStart(); /*MUST BE CALLED */

    ExitThread, 0); /* MUST BE CALLED*/

    }

    If you choose to not use a synchronized startup for your NLM program, you must limit your main() function to the following:

    main ()

    {

    ExitThread (TSR_THREAD,);

    }

  2. If you use the Metroworks IDE, the Synchronized linker option can be turned on by clicking the following:
    ALT+F7 > NLM Linker > Flags > Synchronize
  3. Do not use the standard malloc(), realloc(), or free() calls directly. Java provides the following macros in sys_api.h instead:

    Using these macros gives you free resource tracking. This also lets the memory used by your NLM program use Virtual Memory in NetWare 6.5. In some instances, you might prefer memory returned from malloc, such as buffers used for callbacks or ECBs.

  4. When you link your NLM, you might get the following errors:

    Warning! W1008: cannot open math387s.lib: No such file or directory
    Warning! W1008: cannot open noemu387x.lib: No such file or directory
    Warning! W1008: cannot open emu387x.lib: No such file or directory
    Warning! W1008: cannot open clib3s.lib: No such file or directory

    If you find the correct libraries to correct for these warnings, you'll link in a bad prelude.obs and things will not work properly. If you are using C++, see Item 5 below. To prevent these warnings, add the following Makefile option:

    Option NoDefaultLibs

  5. If you are using C++, add the following lines to the link file:

    LIBPath $(WATCOM)\lib386;$(WATCOM)\lib386\netware;

    LIBFile $(WATCOM)\lib386\plbx3s.lib

    Remove the $(PRELUDE) entry from the file directive.

  6. If you used the word stub in the name of any of your native method classes, change sedscript to ensure that it doesn't corrupt your .EXP file.

Using WATCOM 11.0 Compiler Flags for Native Method NLM Programs

Optimized flags are

/zp=1 /ri /ei /5s /or /ot /w3 /s /zq /ez

Debug flags are

/zp=1 /ri /ei /d2 /od /3s /w1 /s /zq /ez

IMPORTANT:  /ri and /ei are critical for building native method NLMTM programs.



  Previous Page: Prerequisites  Next Page: Source-Level Debugging