Be careful with JVM library location while building JNI based code

In case you want to compile JNI based code on macOS, be careful. Pay attention to @rpath.

If you compile the code like this (it will work in Linux)

ld -L${JAVA_HOME}/lib/server -ljvm ...

you will end up with reference to /usr/local/lib/libjvm.dylib. You will end up with lots of issues as code might be running to some extent.

To make sure your code is properly linked with version you really want to use, make sure to use -rpath

ld -rpath ${JAVA_HOME}/lib/server -ljvm ...

This time, you will use libjvm.dylib that is coming from the location you are interested in.