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 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM