

test.Įt voila, job done, if everything is OK you should see something like this: $. From the same terminal where you have executed the command above, just type.Before running test, you need to set LD_LIBRARY_PATH with the following instruction:Įxport LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/server/.If the compilation is successful, you should get an executable called test. The two -I directives tell where to find jni.h and jni_md.h the -L (and -l) directive are used by the linker to find libjvm.dylib.

You can remove the backslash at the end of each line if you write the command on a single line. L/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/server/ \ I/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/include/darwin \ I/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/include \ The command on my machine (Mac OSX Mavericks, Java 1.8, gcc) is the following: Compile the C++ file: this is slightly more complicated because you need to specify various paths.Javac com/example/simple/SimpleJNITest.java Compile the Java class: this is easy, just type.The main problem is getting the correct location of the various header files and libraries… To make the whole thing run, save the code above in a file (call it test.cpp) and do the following: Package import import public class SimpleJNITest
