HP-UX Programmer's Guide for Java 2

Table Of Contents
NOTE: You are required to supply either -Aa or -Ae as a command-line option to
the C compiler. The Java™ header files that you must include require support for ANSI
C prototypes.
Create the shared library containing the native method implementation:
PA-RISC:
$ aCC -b -o libaCCImpl.sl aCCImpl.o \
-lstd -lstream -lCsup -lm
(see below for Integrity)
Output:
libcImpl.sl
Use libcImpl.so on Integrity
To execute the Java™ program, you must set the SHLIB_PATH environment variable
to contain the location of the directory that contains libcImpl.sl (libcImpl.so on
IPF). SHLIB_PATH is the HP-UX name for LD_LIBRARY_PATH and can contain a list
of directories each separated by colons.
$ export SHLIB_PATH=.:$SHLIB_PATH
$ <java_dir>/bin/java TestJava2CallingNative cImpl
Library cImpl successfully loaded
Calling sayHelloWorld
C says HelloWorld via stdio
All done
Sample Java™ calling native method implementation in HP aC++
Here is a sample Java™ program that calls a native method which has a C++
implementation. This C++ example will use the aC++ compiler. HP has two different
C++ compilers, an older cfront-based product and a newer aC++ compiler. You can tell
which C++ compiler you are using by the name of the driver. The older cfront based
product uses CC as the driver, while the newer aC++ compiler uses aCC as the name
of the driver. The official HP product names for these two C++ compilers are HP C++
for the cfront-based product and HP aC++ for the new C++ compiler.
NOTE: In the HP-UX SDK, for the Java™ 2 Platform there is support for the HP aC++
compiler, but not for the older cfront HP C++ compiler. Since the HP-UX SDK, for the
Java™ 2 Platform contains C++ libraries built with the HP aC++ compiler, any user
shared libraries compiled with cfront are not compatible. Therefore, you have to
recompile your shared libraries with HP aC++ if you intend to use them with the HP-UX
SDK for the Java™ 2 Platform.
//
// TestJava2CallingNative.java
//
class TestJava2CallingNative {
Java™ calling a native (non-Java) method 49