Loading JNI libraries on the Mac

I’ve been trying to build a simple JNI library from C code on the Mac (Snow Leopard). Compiling it seems pretty straightforward, but the Java library loader isn’t happy. I can call

System.load("/tmp/jnitest.jnilib");

which works fine, or

System.loadLibrary("jnitest")
// or
System.loadLibrary("jnitest.jnilib")

with java.library.path set to “/tmp”, which doesn’t work.

I’ve given up trying to understand it for now. I spent way too long googling on the Intertubes for information, which points to problems with Java 1.6 on Snow Leopard, but I didn’t find anything that was even consistent with this behavior. On the other hand, I can at least make progress for the moment, since the JNI calls work.

Tags: , , ,

One Response to “Loading JNI libraries on the Mac”

  1. Fallik says:

    If the libray name is “jnitest” the library filename should have a prefix and a suffix, ie: libjnitest.jnilib

    So try to use:

    System.load(”some-path/libjnitest.jnilib”);

    OR

    System.loadLibrary(”jnitest”);

    In this case you have to add the libjnitest.jnilib file in the java library path (f.e.: /usr/lib/java/)

    Hope it helps

Leave a Reply