java2db

Steps to compile and execute java code from PHP ( run java in PHP )



The easy way to compile and run java code from PHP , use either shell_exec() or exec()  predefined functions from PHP .

 

we used xampp server to test the application.

 

Steps to compile and execute java code from PHP Steps to compile and execute java code from PHP :

 

Steps to compile and execute java code from PHP Step 1 : Check the web server , whether it is a java enabled server or not. If yes , no need to copy the java home, otherwise  copy the entire java home directory to the server home directory.

 

 

Steps to compile and execute java code from PHP Step 2 : Set the java environment to the top of the PHP file that you are going to execute.See the example below.

 

 

 

Steps to compile and execute java code from PHP Step 3 :  Copy the java file (Example  Hello.java) to the web server location  .

 

 

Steps to compile and execute java code from PHP Step 4 : Compile the java file using shell_exec(“javac  “Enter valid java file path”  2>&1″);

 

 

 

Steps to compile and execute java code from PHP Step 5 : Execute the compiled java class using  $OUTPUT = shell_exec(“java “Enter valid java class file path” 2>&1″);

 

 

 

 

Steps to compile and execute java code from PHP Step 6 : Print the output using echo $OUTPUT , so the server will send response to the browser window.

 

 

Another way is the PHP-java bridge .It is good to compile and execute a java file from PHP.

Don’t try to do the above process in sharing servers. It might have chances for server hacks .



Related Posts :
   [will not be published]



^ <