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.
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() |
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 to 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:
copy nwnative.nlm G:\java\bin
Copy the classes to G:\java\classes, then at the command prompt in Windows enter:
copy *.class g:\java\classes
If your CLASSPATH variable is correct, you can run JNI by entering the following at the command prompt:
java NWTest
To unload JNI, 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 to not 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.5. 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 are using C++, see Item 5 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 NLMTM programs.