简体   繁体   中英

Executing Java Class from php web page in Windows Virtual Machine

I have a windows virtual machine in which I installed Bitnami Apache Web Server. I also have java class compiled as "myprogram.jar". I ran the jar file in the virtual machine's command prompt:

java -jar "C:\\Program Files\\Bitnami\\wampstackXXX\\apache2\\htdocs\\test\\myprogram.jar"

and it is working fine. But now I have to run the java command from a php file ("run.php"). Here is the code snippet:

<?php 
   $cmd = "java -jar ".getcwd()."\myprogram.jar"
   echo $cmd;
   $output = shell_exec($cmd);
   echo $output;
?>

I use getcwd() to get the working directory of the php site in which I put the jar file in. I put this "run.php" file in the "C:\\Program Files\\Bitnami\\wampstackXXX\\apache2\\htdocs\\test" folder. But when I access the php file from my web browser, the java command is not firing. Is there something wrong that I did here?

Found the solution here in on of the threads

<?php
    chdir('C:\Program Files\Bitnami\wampstackXXX\apache2\htdocs\test');
    exec('java -jar myprogram.jar');
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM