简体   繁体   English

Mac OS X Lion:VM初始化期间发生错误无法加载本机库:libjava.jnilib

[英]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. 在BASH中运行“java -version”会产生正确的结果。 However, when I try the same command using the shell_exec() command from a PHP script on apache, I get: 但是,当我在apache上使用PHP脚本中的shell_exec()命令尝试相同的命令时,我得到:

"Error occurred during initialization of VM Unable to load native library: libjava.jnilib" “VM初始化期间发生错误无法加载本机库:libjava.jnilib”

I've tried all the usual fixes for this problem (changing symbolic links, unsetting env variables). 我已经尝试了所有常见的修复此问题(更改符号链接,取消设置env变量)。

I'm also quite sure both BASH and the script are using the same binary. 我也很确定BASH和脚本都使用相同的二进制文件。 "which java" yields the same result. “哪个java”产生相同的结果。

Any thoughts on how I could get "java -version" to work? 关于如何让“java -version”工作的任何想法?

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. 您可以通过将DYLD_LIBRARY_PATH环境变量设置为该shell exec的一部分,向OSX提供有关在何处找到该库的提示。 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. 它与使用相同的二进制文件无关,但无论该二进制文件是否能够在用完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. 您将看到libjava.jnilib所在的位置,并将该路径添加到您的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. 免责声明:使用DYLD_LIBRARY_PATH有各种各样的阵营,它可能(像许多事情一样)是一种安全风险。 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. 但是,由于在这种情况下,shell_exec()用于执行二进制文件而不使用绝对路径,因此DYLD_LIBRARY_PATH是最不安全的问题。

This worked for me: 这对我有用:

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

References: 参考文献:
- https://drupal.org/node/1257654 - https://drupal.org/node/1257654
- Calling java from PHP exec - 从PHP exec调用java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用MAMP的Mac OSX上的PHP中的shell_exec()提供了VM初始化期间发生的错误无法加载本机库:libjava.jnilib - shell_exec() in PHP on Mac OSX using MAMP gives Error occurred during initialization of VM Unable to load native library: libjava.jnilib VM初始化期间发生错误;无法加载本机库:找不到依赖库 - Error occurred during initialization of VM;Unable to load native library:Can't find dependent libraries 在 Mac OS X Lion 中初始化 Java VM 时出错 - Error initializing Java VM in Mac OS X Lion 尝试在Mac OS X上加载JNA库时出现“无法加载库:在资源路径中找不到JNA本机支持” - “Unable to load library: JNA native support not found in resource path” on trying to load JNA library on Mac OS X 月食错误“ VM初始化期间发生错误” - eclipse error of “Error occurred during initialization of VM ” JNI失败,并显示“ VM初始化期间发生错误” - JNI fails with 'Error occurred during initialization of VM' Linux - Java - VM初始化期间发生错误 - Linux - Java - Error occurred during initialization of VM Java“VM初始化期间发生错误”修复? - Java "Error occurred during initialization of VM" fix? linux 中的“VM 初始化期间发生错误” - “Error occurred during initialization of VM” in linux 获取“VM初始化期间出错” - Getting “Error occurred during initialization of VM”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM