make install part of the build process will
load the native code and C libraries into standard locations.
By default these are
/usr/local/classes for
posix.jar
/usr/local/lib for
libjava_posix.*
In order to run an application using these, appropriate
environment variables must be set. For example, using
bash
CLASSPATH=/usr/local/classes/posix.jar:$CLASSPATH
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export CLASSPATH LD_LIBRARY_PATH
For compilation, only CLASSPATH needs to be set.
Every application must dynamically load the Posix library before any calls to Posix objects are made, by
System.loadLibrary("java_posix");
#includemain() { const int SIZE = 1024; char buf[SIZE]; int nread; while ((nread = read(0, buf, SIZE)) > 0) write(1, buf, nread); }
The Java equivalent is
import posix.Posix;
import posix.PosixException;
public class CopyIO {
public static void main(String argv[]) {
System.loadLibrary("java_posix");
final int SIZE = 1024;
byte buf[] = new byte[SIZE];
int nread;
try {
while ((nread = Posix.stdin.read(buf)) != 0)
Posix.stdout.write(buf, nread);
} catch(PosixException e) {
System.err.println("Error in copy " + e.toString());
}
}
}
The test directory contains further examples.