Previous Page: Developer's Guide  Next Page: Revision History

Tasks


Using Java Native Interface (JNI) on NetWare

The JAVA\BIN directory includes a file named JNI.TAR. When you extract this file, it demonstrates simple native method examples for Java 1.1. This section is an example of how to write native methods for the Java 1.3.1 Virtual Machine on NetWare. It is not a comprehensive tutorial on writing native methods.


Tools Required


Description of Files

File Description

MAKEFILE

Make file for NetWare

NWNATIVE.JAVA

Native method java class

NWTEST.JAVA

Test class

README.TXT

JNI section of this file

NWIMPL.C

Native method C implementation

NWMAIN.C

CLIB NLM wrapper - main()


Installing JNI

After you build the example and map your server volume SYS: to drive G:, complete the following steps 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 the following at the Windows command prompt:

    copy nwnative.nlm G:\java\bin

  3. Copy the classes to G:\JAVA\CLASSES by entering the following at the command prompt:

    copy *.class g:\java\classes


Building JNI

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

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

    nmake clean


Running JNI

To ensure that the CLASSPATH variable isn't corrupted by extra spaces, misplaced or missing semicolons, or incorrect data, enter the following at the server console:

java NWTest


Unloading JNI

To unload, 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 (NLMTM) 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 not to use a synchronized startup for your NLM program, you must limit your main() function to the following:

    main ()

    {

    ExitThread (TSR_THREAD,);

    }

  2. Do not use the standard malloc() or realloc() or free() calls directly. Java provides the following macros in sys_api.h instead:
    • sysMalloc - same parameters as malloc()
    • sysFree - same parameters as free()
    • sysRealloc - same parameters as realloc()
    • sysCalloc - same parameters as calloc()

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

  3. 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 noemu387.lib: No such file or directory
    • Warning! W1008: cannot open emu387.lib: No such file or directory
    • Warning! W1008: cannot open clib3s.lib: No such file or directory

    If you find the correct libraries, you'll link in a bad prelude and things will not work correctly. If you're using C++, see Item 4 below. To prevent these warnings, add the following Makefile option:

    Option NoDefaultLibs

  4. 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.

  5. 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.

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 NLM programs.



  Previous Page: Developer's Guide  Next Page: Revision History