I need to run a single java program (which will change the content of some text files) on my new website. What's the easiest way to do that for example using php code? Do I need to install JVM or any other software in order for this to work? Please guide on how to do this step by step if possible.
Asked
Active
Viewed 897 times
-4
-
What you want is a web application : http://stackoverflow.com/questions/1385105/how-do-i-get-started-building-web-apps-with-java – Limit Jan 22 '16 at 11:13
1 Answers
0
You have to install a Java Runtime Environment (JRE) on your server to be able to run a java program.
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
To execute a java program in php, you can simply use the exec()
function :
exec("java -jar yourProgram.jar");

Patrick
- 831
- 11
- 25
-
So if I have access to the server only by FTP client (the page is hosted on someones server) should i download JRE version for 32-bit linux and then copy it to the server using FTP? – OrdinaryProgrammer Jan 22 '16 at 11:29
-
Yes it should be possible if you send the uncompressed folder through FTP. But maybe the `java` command will not be recognized on the server so you will have to put the whole path to java in your php command (something like `exec("/install_dir/jre1.8.0_71/bin/java -jar yourProgram.jar");` – Patrick Jan 22 '16 at 16:30