This is a trivial example of a JNI native method intended to provide a comparison with the GCJ CNI example. The source files are identical to the jni-kaffe example; only the Makefile has changed. This was built using GCJ 3.0 on a Red Hat 6.0 system, and run by installing libsampNat.so in a directory in the library path and running the sample executable. Note that the current implementation will not work if you simply link the native calls into the executable and omit the loadLibrary call from the application. This is due to the implementation of JNI method lookup in java/lang/natRuntime.cc. ==> Makefile <== all: sample libsampNat.so libsampNat.so: sampNat.o gcc -shared -o libsampNat.so sampNat.o sampNat.o: sampNat.c sample.h gcc -c sampNat.c sample.h: sample.class gcjh -jni sample sample.class: sample.java gcj -C sample.java sample: sample.class gcj -fjni -o sample sample.class --main=sample clean: rm -f sample.h sample.class sample sampNat.o libsampNat.so ==> sampNat.c <== #include #include "sample.h" #include void Java_sample_myNative(JNIEnv* env, jobject this, jstring s) { jclass cls; jfieldID fid; jobject obj; jmethodID mid; printf("From C\n"); cls = (*env)->FindClass(env, "java/lang/System"); if (cls == 0) { printf("java/lang/System lookup failed\n"); return; } fid = (*env)->GetStaticFieldID(env, cls, "out", "Ljava/io/PrintStream;"); if (fid == 0) { printf("java/lang/System::out lookup failed\n"); return; } obj = (*env)->GetStaticObjectField(env, cls, fid); if (obj == 0) { printf("GetStaticObjectField call failed\n"); return; } cls = (*env)->GetObjectClass(env, obj); if (cls == 0) { printf("GetObjectClass(out) failed\n"); return; } mid = (*env)->GetMethodID(env, cls, "println", "(Ljava/lang/String;)V"); if (mid == 0) { printf("println method lookup failed\n"); return; } (*env)->CallVoidMethod(env, obj, mid, s); } ==> sample.java <== public class sample { public native void myNative(String s); public void myJava(String s) { s = s + ", Java"; System.out.println(s); } public static void main(String args[]) { sample x = new sample(); x.myJava("Hello"); x.myNative("Hello, Java (from C)"); x.myJava("Goodbye"); } static { System.loadLibrary("sampNat"); } } /