HP-UX Programmer's Guide for Java 2

Table Of Contents
$ cc -O -c -Ae +u4 -mt -I<java_dir>/include \
-I<java_dir>/include/hp-ux c_main.c
Output:
c_main.o
Link the main executable.
cc -z -o c_main c_main.o \
-L<java_dir>/jre/lib/PA_RISC2.0/hotspot \
-ljvm -lpthread -llwp
On Integrity, the command to the main program would look like this:
$ cc -z -o cmain cmain.o \
-L<java_dir>/jre/lib/IA64/hotspot \
-ljvm -lpthread
Output:
c_main
NOTE: If you are using SDK 1.2 or 1.3 and your C main is linked EXEC_MAGIC so as
to be able to address more than 1GB of private data, you must use the Hotspot JVM,
or use the Classic JVM with the -nojit option. The JIT compiler in Classic 1.2 and 1.3
is not compatible with EXEC_MAGIC.
To execute the C main program, set the SHLIB_PATH environment variable so the jvm
libraries can be loaded.
$ export SHLIB_PATH=<java_dir>/jre/lib/PA_RISC2.0:\
<java_dir>/lib/PA_RISC2.0/hotspot
$ export CLASSPATH=.
./c_main
TestNonJavaCallingJava.printInt received: 100
To access Integrity libraries, change PA_RISC2.0 to IA64.
Sample native calling Java™ implementation in HP aC++
Here is the sample HP aC++ program. This program will use the C++ object-oriented
interface provided in the JVM Invocation Interface to create a new JVM, find a class
named TestNonJavaCallingJava2, and find a Java™ method named printInt,
and invoke the method with an argument of 100.
NOTE: This program works as is for SDK 1.4.2. However, if you wish to take advantage
of the new JNI features in 1.4.2, in the example below you should change the line
vm_args.version = JNI_VERSION_1_2; to vm_args.version =
JNI_VERSION_1_4;
//File: aCC_main.C
//
//Example : aC++ Source File as the Main
Native (non-Java) calling Java™ methods 55