doulong6761 2014-08-10 17:41
浏览 73
已采纳

试图从PHP运行一个jar

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:

How to run a jar from a web server using PHP

Run Java class file from PHP script on a website

why exec('java -jar file.jar') dont work on browser but works on command line?

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.

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;

The result I have is:

Failed
Result:

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 version: 1.7.0_51 and PHP version: 5.4.26

I would highly appreciate any comments on this.

  • 写回答

3条回答 默认 最新

  • dongye1143 2014-08-13 08:18
    关注

    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.

    Calling Python scripts from Php always works for me.

    This post helped me in the past:

    Python: How can I execute a jar file through a python script

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图