Page 1 of 1

Help Executing a jar file

Posted: Sat Sep 02, 2006 2:24 am
by Tommaso
Hello, I am glad to be on the forums, but please have patience with me, because i just started learning PHP

So, here is the situation: I would like to have a php "script" that executes a jar file that produces a text file. Once the text file is produced, another PHP script reads the file, and displays it in HTML. I created the jar, and both scripts, but i cannot get them to work properly.

- If i manually add the text file, then the read scrip works perfectly, so there is nothing wrong with that.
- if i launch the jar file from the terminal with the linux terminal command java -jar /var/www/html/JarFolder/test3.jar then the jar is successfully executed, and the text file is created. Also, the jar file, and its entire directory has full read, write, and execute privileges for all users
- if i use my run script, however, the jar file does not execute and the text file is never produced :( I would appreciate any help, so that i can fix this problem. Thanks

Here is my run script:

Code: Select all

<html>

<head>

<title>Jar File Runner</title>

</head>

<body>



<?php

echo "<h2>Jar File Status</h2>";

$JarName = "test3.jar"; /tthis is the name of the file, unfortunately i have already checked and it is correct
$Path = getcwd();
$Command = 'java -jar ' . $Path . "/" . $JarName;

exec($Command);

echo " - The Jar File <i>" . $JarName . "</i> is running", "<br>", " - <a href='View.php'>View Output</a>";
echo "<br><br><i>Command Executed:</i>", $Command;

?>

</body>

</html>
ps- if i copy the output of the last echo statement in the code above into my linux terminal and hit enter, the jar file executes fine, so its not a syntax error...

Posted: Sat Sep 02, 2006 4:12 am
by timvw
(*) Assuming that the PHP script is actually run by the webserver since you also have html etc in the 'run-script'...

The webserver user doesn't have the java executable in his path... Try to use a fullpath to the java executable...

eg: $command = '/usr/lib/j2sdk1.5-sun/bin/java -jar'...

Posted: Sat Sep 02, 2006 7:45 pm
by Tommaso
Finally got it working, the reason for failure was due to a a permissions problem. I had to turn off SELinux...ahhh, its frustrating when the problem is not your fault...

Well, thanks for the suggestion anyways.

Posted: Sat Sep 02, 2006 11:39 pm
by timvw
From what i remember from SELinux you have to:
- Allow the use of shared libraries with Text Relocation
- Allow executables to run with executable stack