Java 1.6 由后台 Symfony 任务调用时损坏
我有一个 Symfony 任务,它生成一些文件,调用 exec 到 jar,然后解析输出。 jar 从命令行运行良好,任务从命令行运行良好。
问题:
我在基于表单提交的操作中调用该任务。我让操作在后台启动一个新的 php 进程来运行任务,无论它生成的页面现在执行什么操作。
当到达 java 调用时,说 exec(java -version);它输出如下:
Error occurred during initialization of VM
Unable to load native library: libjava.jnilib
我觉得这与我启动任务时调用 php 的方式有关,但我不明白为什么它没有与使用命令行时相同的库。
如何让 java 从“后台”Symfony 任务运行?
注释:
它曾经工作顺利,直到我将 mamp 从 1.9.6 升级到 2.0.3。
我看过: 损坏的 Java Mac 10.6 但由于我可以从命令行很好地运行它,这似乎是一个不同的问题。
我还查看了 从shell_exec() 权限被拒绝 但我不认为权限是这里的问题。
更新:
我已将问题范围缩小到 MAMP 并从浏览器访问 php。
<?php
echo exec("java -version")
...
从命令行调用时有效,但通过浏览器打开 php 文件时无效。因此,MAMP 的配置方式导致了该问题。
这是环境信息:
- 变量值
- SHELL /bin/bash
- TMPDIR /var/folders/YH/YH+uW3hDHZyxQ5AiUtr0T++++TI/-Tmp-/
- Apple_PubSub_Socket_Render /tmp/launch-3rr9ZI/Render
- USER myuser
- COMMAND_MODE unix2003
- SSH_AUTH_SOCK /tmp/启动-zinaMI/Listeners
- __CF_USER_TEXT_ENCODING 0x1F5:0:0
- 路径 /usr/bin:/bin:/usr/sbin:/sbin
- PWD /
- HOME /Users/myuser
- SLVL 2
- DYLD_LIBRARY_PATH /Applications/MAMP/Library/lib:
- LOGNAME myuser
- DISPLAY /tmp/launch-FYrw70 /org.x:0
- _ /Applications/MAMP/Library/bin/httpd
Dyld 似乎存在于此处。我需要找到一种方法将其从 mamp 的环境中取消设置。
已解决
我已经找到了解决方案。这看起来像是一个黑客,但它确实有效。我会将其发布在这里,以防其他人遇到同样的问题。
正如 Broken Java Mac 10.6 提到的 DYLD_LIBRARY_PATH 必须未设置。不知道为什么,它似乎在 Unix 系统上需要,但在 MacOSX 上不需要。
如果 MAMP 设置为 /Applications/MAMP/Library/lib 以下是禁用它的方法: 编辑 /Applications/MAMP/Library/bin/envvars 并注释掉以下行,
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
使其看起来像这样:
#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
这应该可以解决问题,并且 java 1.6 可以正常运行。
这是黑客攻击吗?或者这是 MAMP 中的一个错误?如果您知道解决此问题的更好方法,请回答。
I have a Symfony task that generates some files calls exec to a jar and then parses the output. The jar runs fine from the command line, the task runs fine from the command line.
The problem:
I call the task in an action based on a form submission. I have the action start a new php process in the background to run the task regardless of what the page the spawned it does now.
When it gets to the java call, say exec(java -version); it outputs this:
Error occurred during initialization of VM
Unable to load native library: libjava.jnilib
I feel like it has to do with the way I call php when I start the task but I'm lost as to why it wouldn't have the same libraries as when I use the command line.
How can I make java run from the 'background' Symfony task?
Notes:
It used to work with no hitch until I upraded mamp from 1.9.6 to 2.0.3.
I've looked at:
Broken Java Mac 10.6
but since I can run it fine from the command line it seems to be a different issue.
I've also looked at Execute symfony task command from the shell_exec() permission denied but I don't think permissions are the issue here.
Update:
I've narrowed down the problem to MAMP and getting to php from the browser.
<?php
echo exec("java -version")
...
Will work when called from the command line but not when the php file is opened through the browser. So the way MAMP is configured is causing the issue.
Here's the environment info:
- Variable Value
- SHELL /bin/bash
- TMPDIR /var/folders/YH/YH+uW3hDHZyxQ5AiUtr0T++++TI/-Tmp-/
- Apple_PubSub_Socket_Render /tmp/launch-3rr9ZI/Render
- USER myuser
- COMMAND_MODE unix2003
- SSH_AUTH_SOCK /tmp/launch-zinaMI/Listeners
- __CF_USER_TEXT_ENCODING 0x1F5:0:0
- PATH /usr/bin:/bin:/usr/sbin:/sbin
- PWD /
- HOME /Users/myuser
- SHLVL 2
- DYLD_LIBRARY_PATH /Applications/MAMP/Library/lib:
- LOGNAME myuser
- DISPLAY /tmp/launch-FYrw70/org.x:0
- _ /Applications/MAMP/Library/bin/httpd
Dyld seems to be present in here. I need to find a way to unset it from mamp's environment.
Solved
I've figured out a solution. It seems like a hack but it worked. I'll post it here just incase anyone else runs into the same problem.
As Broken Java Mac 10.6 mentions the DYLD_LIBRARY_PATH must be unset. Not sure why, it seems to be needed on Unix systems but not MacOSX.
If MAMP sets to /Applications/MAMP/Library/lib here's how to disable it:
Edit /Applications/MAMP/Library/bin/envvars and comment out the following lines
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
So that it looks like this:
#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
This should fix the problem and java 1.6 can run fine.
Is this a hack? or is this a bug in MAMP? Please answer if you know a better way to solve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是@paaat添加的解决方案。我发帖只是为了将这个问题从未回答的列表中删除。
它看起来像这样:
这应该可以解决问题并且 java 1.6 可以正常运行。
请务必重新启动 MAMP 安装以使更改生效。
This is the solution of @paaat added. Im just posting to get this question out of the unanswered list.
So that it looks like this:
This should fix the problem and java 1.6 can run fine.
Be sure to restart your installation of MAMP for the changes to take effect.
这有效!我正在运行的 MAMP 版本是 2.1.3,但是文件中的内容有所不同:
This worked! The version of MAMP I'm running, 2.1.3, however has a different contents in the file:
这对我有用:
参考文献:
- https://drupal.org/node/1257654
- 从 PHP exec 调用 java
This worked for me:
References:
- https://drupal.org/node/1257654
- Calling java from PHP exec