Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X Lion: Error occurred during initialization of VM Unable to load native library: libjava.jnilib

Tags:

java

macos

Running "java -version" in BASH yields the correct result. However, when I try the same command using the shell_exec() command from a PHP script on apache, I get:

"Error occurred during initialization of VM Unable to load native library: libjava.jnilib"

I've tried all the usual fixes for this problem (changing symbolic links, unsetting env variables).

I'm also quite sure both BASH and the script are using the same binary. "which java" yields the same result.

Any thoughts on how I could get "java -version" to work?

like image 739
Rui Jiang Avatar asked Jul 27 '11 20:07

Rui Jiang


1 Answers

You can give OSX a hint as to where to find that library by setting the DYLD_LIBRARY_PATH environment variable as part of that shell exec. It has nothing to do with them using the same binary, but whether or not that binary can find the libraries it is linked to when run out of apache. You can see what libraries a binary links with by running:

otool -L <binary>

You will see where libjava.jnilib resides and add that path to your DYLD_LIBRARY_PATH. There may be many libraries you need to add paths for.

Good luck!

Disclaimer: There are various camps around the use of DYLD_LIBRARY_PATH, it can possibly (like many things) be a security risk. However since in this case shell_exec() is been used to execute binaries AND is doing so without using an absolute path, DYLD_LIBRARY_PATH is the least of security concerns.

like image 90
Justin Avatar answered Oct 30 '22 12:10

Justin