Page 1 of 1

php and java

Posted: Sat Nov 25, 2006 2:32 am
by Gawd
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi,

i am kind of newbie in php. i am trying to run java program from php whithout having to instal  php/java bridge on linux

bascally i am using the following commands

Code: Select all

<?php

$r1 = exec("javac hello.java");
$r2 = exec("java hello");

echo $r1;
echo $r2;
?>

when i open this php file on the browser i get nothing. just an empty page. the exec command works with system file commands like ls, cat...

i have tried using other php command like passthru but i still get the same result

any ideas or suggestions? your help is appreciated


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Nov 25, 2006 3:41 pm
by Chris Corbyn
You probably need to set some Java compiler environment variable like $CLASSPATH and $JAVA_HOME. Just a guess.

Above those exec() calls try:

Code: Select all

<?php

//If this is a linux server
exec("export CLASSPATH=:.:/opt/java/lib:/opt/java/jre/lib:/opt/java/lib/tools.jar");
exec("export JAVA_HOME=/opt/java");

//or if this is a windows server
exec("set CLASSPATH=:.: .....  ");
exec("set JAVA_HOME= ..... ");

$r1 = exec("javac hello.java");
$r2 = exec("java hello");

echo $r1;
echo $r2;
?>

Posted: Sat Nov 25, 2006 3:42 pm
by Chris Corbyn
Also make sure you're giving the absolute path. The locations are relevant to the parent PHP script being run.

RE: PHP and java

Posted: Sun Nov 26, 2006 12:06 am
by Gawd
i was actually using a 1.4 vm to run a java file compiled with a 1.5 VM

i used a retrotranslator. this seems to have fixed the problem.

http://retrotranslator.sourceforge.net/



Thank you for all the replies