在PHP中运行Java类文件(在命令行中成功运行但不在PHP中运行)

I know the approach to run external programs in PHP is to use exec() or shell_exec(). I have tried them both, even system(), but none of these seem to be working. I have added all the required jar files to my "jre/ext" folder and running the java class file is successful in command line.

So in command line, after compiling, my command to run is "java MyProgram". In PHP, I tried echo exec('java MyProgram') and shell_exec('java MyProgram').

I have a simple sample Hello_World Java file and PHP is able to run that successfully. I am thinking may be the issue can be I have Apache POI jar files that are needed for the java class, but I don't know how should I resolve or explore further now.

Thanks in advance!