试图从PHP运行一个jar [英] Trying to run a jar from PHP
问题描述
在阅读本网站上与我所遇到的完全相同的问题相关的一些帖子后,我发现他们都没有给我一个成功的结果:
After reading some of the posts in this website related to exactly the same issue I've got, I found that none of them were giving me a successful result:
为什么exec('java -jar file.jar')不能在浏览器上运行但是在命令行上工作?
我使用的是Windows Server 2008 R2数据中心,64位,它是来自AWS的EC2实例。
我用来在php文件中运行我的jar的命令是exec,它适用于任何phyton脚本和普通的.exe程序。但是当谈到一个罐子时,它什么都不做。
I'm using a Windows Server 2008 R2 datacenter, 64 bits, it's an EC2 instance from AWS. The command that I use to run my jar in a php file is exec, which works for any phyton script and normal .exe programs. But when it comes to a jar, it does nothing.
这是我的代码(我的jar需要5个参数):
This is my code (my jar needs 5 parameters):
$script = "java -jar scripts/IDW.jar 5 none 2 values_grid values";
$result = exec($script, $output);
if ($result) {
print_r($output);
}
else {
echo "Failed";
}
echo "<br/>Result: ". $result;
我的结果是:
Failed
Result:
当我运行jar时在控制台上,它运行得很好,但不是来自PHP,这意味着我在上面的Php代码中传递了正确的参数值。
When I run the jar on console, it runs perfectly, but not from PHP, which means I am passing the right parameter values at the above Php code.
Java版本:1.7.0_51和PHP版本:5.4.26
Java version: 1.7.0_51 and PHP version: 5.4.26
我非常感谢对此提出的任何意见。
I would highly appreciate any comments on this.
推荐答案
这不是一个直接的答案,但如果从Php调用java在任何情况下都不起作用,您也可以从Python脚本运行jar文件。我的意思是Php - > Python - > jar。
This is not a straight answer, but if calling java from Php does not work under any circumstances, you can also run jar files from Python scripts. I mean Php --> Python --> jar.
从Php调用Python脚本总是对我有用。
Calling Python scripts from Php always works for me.
这篇文章过去曾帮助过我:
This post helped me in the past:
这篇关于试图从PHP运行一个jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!