I am having troubles with the passthru() command when executing Java programs. More specifically with setting the LD_LIBRARY_PATH using passthru.
I tried:
- setting the .so file path directly like this:
passthru("java -Djava.library.path='.:/path/to/directory/of/.so/object' " HelloWorld);
writing a shell script which sets the LD_LIBRARY_PATH,then executing the shell script using passthru.
acessing the /etc/profile file and adding the "export LD_LIBRARY_PATH..." line in the document.
These are just few solutions I found online which I thought would work, but none worked. I believed the problems come from concatenation stuff in the passthru command as I saw on several sites stuff like that:
$command = 'export LD_LIBRARY_PATH="' . $path_to_library_dir .'"; ' . $path_to_binary; passthru($command);
which I also tried.But I dont know what am doing wrong.
Please, can anyone help?
Thank you!
EDIT 1
Using @lexmihaylov suggestion:
Hi, Thank you for replying. Actually I get an "java.lang.UnsatisfiedLinkError:/usr/lib/libjpcap.so". So that's why I am trying to set up the LD_LIBRARY_PATH to my .so object.
From your answer I tried:
$Path_to_library_dir = '/usr/lib64/jpcap';
$Path_to_binary = '/usr/lib64/jpcap/libjpcap.so';
$command = 'LD_LIBRARY_PATH="' . $Path_to_library_dir .'" '.$Path_to_binary;
passthru($command);
$java_execution = "java myjavaprogram 2>&1";
echo passthru($java_execution,$output); echo $output;
I still get the same java.lang.UnsatisfiedLinkError. But if I set the LD_LIBRARY_PATH directly in my terminal, my java program works fine when executed via terminal.
Thank you for helping!