Note that there are some explanatory texts on larger screens.

plurals
  1. POExecuting Java JAR from PHP will not work
    primarykey
    data
    text
    <p>I have a java program that generates an HTML file. The Java program takes two input parameters: file1 and file2, the output file is specified by the "--file=". </p> <p>When executed from the command line (UNIX, Mac OS 10.6.2) it looks like this:</p> <pre><code>"java -jar program.jar http://my.testsite.com/test1.html http://my.testsite.com/test2.html --file=/path/to/jar/new_file_1274119954.html</code></pre> <p>Executing the program form the command line generates the file "new_file_TIEMSTAMP.html" </p> <p>Now I want execute this same line form PHP so I created the following script:</p> <pre><code> $file1 = 'http://my.testsite.com/test1.html'; $file2 = 'http://my.testsite.com/test2.html'; $newFile = '/path/to/jar/new_file_'.time().'.html'; <strong>system</strong>("java -jar program.jar $file1 $file2 --file=$newFile"); $handle = fopen($newFile, "r"); $output = fread($handle, filesize($newFile)); echo "$output"; </code></pre> <p>Like you can see, I am not really interested in the console output, but rather in the file that is generated by the program.</p> <p>I have also use the following calls to execute the console command but neither of them works when executing this PHP script from my browser.</p> <ul> <li><a href="http://php.net/manual/en/function.system.php" rel="nofollow noreferrer">system()</a></li> <li><a href="http://php.net/manual/en/function.exec.php" rel="nofollow noreferrer">exec()</a></li> <li><a href="http://php.net/manual/en/function.shell-exec.php" rel="nofollow noreferrer">shell_exec()</a></li> </ul> <p>I am not sure if there is some special setting that I need to enable in my php.ini, or is something I am doing wrong, but I am not sure what to do now.</p> <p>Your help is appreciated</p> <p>PD:</p> <p>One error message I do get when using the <strong>system</strong> call is the following: <i> javax.xml.transform.TransformerException: org.xml.sax.SAXException: setResult() must be called prior to startDocument(). </i></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload