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 the Java 1.4.0 Virtual Machine on NetWare. It is not a comprehensive tutorial on writing native methods.
| 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 NLM wrapper - main() |
After you unpack the package, complete the following:
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.
Enter the following at a Windows command prompt:
nmake
The following are the file descriptions:
To clean the build, enter the following at a Windows command prompt:
nmake clean
After you build the example and map your server volume SYS: to drive G:, complete the following steps install JNI:
Check to see if G:\JAVA\CLASSES exists as a directory. If not, enter
mkdir G:\java\classes
Copy the NLM to G:\JAVA\BIN by entering the following command:
copy nwnative.nlm G:\java\bin
Copy the classes to G:\JAVA\CLASSES, and then at the command prompt in Windows enter
copy *.class g:\java\classes
If your CLASSPATH variable is correct, you can run JNI. Enter the following at the command prompt:
java NWTest
To unload, at the server console enter
java -exit
This section contains notes and examples that might be helpful with the JNI process:
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,);
}
ALT-F7 > NLM Linker > Flags > Synchronize
Using these macros gives you free resource tracking. This also lets the memory used by your NLM program use Virtual Memory in NetWare 6. In some instances, you might prefer memory returned from malloc, such as buffers used for callbacks or ECBs.
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're using C++, see Item 4 below. To prevent these warnings, add the following Makefile option:
Option NoDefaultLibs
LIBPath $(WATCOM)\lib386;$(WATCOM)\lib386\netware;
LIBFile $(WATCOM)\lib386\plbx3s.lib
Remove the $(PRELUDE) entry from the file directive.
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.