dsljpwi494719 2019-03-08 10:38
浏览 62

从php调用.jar ...需要服务器配置?

I hope not to duplicate a post but I could not find any details about it.

I developed a java sendMail application (with NetBeans) and correctly compiled the project. I copied everything on my UNIX cloud server in the same path where the php resides where I need to call the .jar. the following is the structure of the path:

/file.php
/SendMail.jar
/lib/javax.mail.jar

When i call file.php (via browser), nothing happens...... I have tried all syntax possible in php......shell_exec....exec....ecc...ecc... below the code I am using:

$java = "/opt/abs/httpd/SendMail.jar";
shell_exec("java -cp ".$java);
echo "Done";

do I have to implement some configuration for the apache server to communicate with java?

where am I wrong?

Thanks in advance!!!

  • 写回答

2条回答 默认 最新

  • doutui2016 2019-03-08 11:15
    关注

    Step 1:

    You should first package the project with every dependency needed in a jar file.

    Step 2:

    Then try running the jar on your local machine using:

    java -jar /path-to-jar/SendMail.jar 
    //once you verify everything is working
    

    Step 3: on your server

    exec('java -jar /path-to-jar/SendMail.jar')
    

    If you wish to run it in background

    exec('java -jar /path-to-jar/SendMail.jar > /log-path/yourservice.log 2>&1)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100