JAVA_HOME and java.library.path

I’m working on a project where I need to set the JAVA_HOME path. Typing which java in the terminal, I get “/usr/bin/java”, but this is actually not the java_home. The right way is to use sudo /usr/libexec/java_home and then input the password of the administrative account of your computer as requested, you will get the java_home path. Mine (OSX Snow Leopard 10.6.8) is /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Then you can use JAVA_HOME=$(/usr/libexec/java_home) to set the java_home path, without literally typing the exact path.
You can then use either echo $JAVA_HOME or env | grep JAVA_HOME to confirm the path.

Another issue I had is with the java.library.path when using Eclipse. Even though I have included all the .jar files in the Eclipse project, I still got UnsatisfiedLinkError in Eclipse saying something is not found in the java.library.path. I had to add an .jnilib file in to the java library path. The safe way to do so without messing up with the java.library.path is to create a new user library in Eclipse project–>properties–>build path. After you create the new user library, click the arrow on the left of the new library title in the following dialog, and change the “native library location” from none to where the .jnilib file is located. Problems solved!