开发者

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

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 ho开发者_C百科w I could get "java -version" to work?


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.


This worked for me:

<?php
  exec('export DYLD_LIBRARY_PATH=""; java -version');
?>

References:
- https://drupal.org/node/1257654
- Calling java from PHP exec

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜