php and java

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gawd
Forum Newbie
Posts: 2
Joined: Sat Nov 25, 2006 2:25 am

php and java

Post 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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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;
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Also make sure you're giving the absolute path. The locations are relevant to the parent PHP script being run.
Gawd
Forum Newbie
Posts: 2
Joined: Sat Nov 25, 2006 2:25 am

RE: PHP and java

Post 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
Post Reply