Mac OS X Lion:VM初始化期间发生错误无法加载本机库:libjava.jnilib [英] Mac OS X Lion: Error occurred during initialization of VM Unable to load native library: libjava.jnilib

查看:172
本文介绍了Mac OS X Lion:VM初始化期间发生错误无法加载本机库:libjava.jnilib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在BASH中运行"java -version"会产生正确的结果.但是,当我从Apache上的PHP脚本中使用shell_exec()命令尝试相同的命令时,会得到:

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:

"VM初始化期间发生错误,无法加载本机库:libjava.jnilib"

"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).

我也很确定BASH和脚本都使用相同的二进制文件. 哪个java"产生相同的结果.

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

关于如何使"java -version"正常工作的任何想法?

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

推荐答案

通过将DYLD_LIBRARY_PATH环境变量设置为该Shell exec的一部分,可以向OSX提供有关在何处查找该库的提示.使用相同的二进制文件与它们无关,但是当用完Apache时,该二进制文件是否可以找到与其链接的库.您可以通过运行以下命令查看二进制链接所使用的库:

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>

您将看到libjava.jnilib所在的位置,并将该路径添加到DYLD_LIBRARY_PATH中.您可能需要添加许多库.

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.

祝你好运!

免责声明:DYLD_LIBRARY_PATH的使用存在各种各样的阵营,它可能(像许多事物一样)存在安全风险.但是,由于在这种情况下,将shell_exec()用于执行二进制文件并且无需使用绝对路径即可执行二进制文件,因此DYLD_LIBRARY_PATH是安全问题中最少的问题.

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.

这篇关于Mac OS X Lion:VM初始化期间发生错误无法加载本机库:libjava.jnilib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆