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:
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.
This is the solution of @paaat added. Im just posting to get this question out of the unanswered list.
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.
Be sure to restart your installation of MAMP for the changes to take effect.
This worked! The version of MAMP I'm running, 2.1.3, however has a different contents in the file:
#if test "x$DYLD_LIBRARY_PATH" != "x" ; then
# DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#else
# DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"
#fi
#export DYLD_LIBRARY_PATH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With