I have already can execute *.java or *.jar on PHP at my xampp, with this code
exec('java -cp stanford-parser.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser stanford-parser-2012-03-09-models\edu\stanford\nlp\models\lexparser\englishPCFG.ser.gz text.txt > result.txt');
it’s localhost in my computer.
And now I want to hosting my coding into website internet. I’m afraid the java don’t want to execute and run the exec line. What should I do to make exec *.java or *.jar can run on website?
I hear that I must install tomcat or javabridge. But I don’t understand. can you help me? thanks very much.
You don’t need tomcat to run the above command, you should be able to run it just like you do on your own machine as long as java is installed on the server you’re running on. Of course, you’ll want to make sure your paths are set correctly, and even then this is not a good idea, especially if you expect it to be hit by a lot of traffic or if it takes a significant amount of time to complete (> 5 seconds).
The easiest way to do this the ‘right’ way is to kick off a long running process (outside of the Apache/php request and set some type of flag or indicator when it is complete. You can have the browser refresh if you want them to be immediately notified when it is completed. A simple way to do this is to run the command above as a background process (append & to the end of the command as shown below). Of course, this leave out a lot of error handling that may need to be done.