This question already has an answer here:
this is my java file.
hello.java
class hello
{
public static void main(String args[])
{
System.out.println("Hello");
}
}
i want to compile and run this file in php. This is my php file.
index.php.
<?php
exec('java'.Hello.java, $output);
if ($resultCode)
{
echo "Result: " . $resultCode . "
";
//echo implode("
", $output);
}
?>
</div>
create jar file
from source and with php, run exec() command and run this command:
java -jar MyJar.jar
You can try this:
<?
exec('java -Xmx1024m -jar "/home/blahblahblah/mydomain/testjava/Test.jar"');
?>
Refer this: http://php-java-bridge.sourceforge.net/doc/how_it_works.php
More examples you can refer from this:
If it is single file compiled Java code (.class), then just run using:
<?php
exec("/path/to/java/bin/java /path/to/your/class/file/hello");
?>
Note: The uncompiled java program (.java) can not be run until it is compiled to runnable file (.class)