Run Java class file from PHP script on a website

The PHP exec() function is the way to go, but you should be very careful in what you allow to executed.. in other words don’t rely on user input as it could potentially compromise your entire server.

Calling the Java application launcher using exec, you can execute any Java application from PHP, e.g.

<?php exec("java -jar file.jar arguments", $output); ?>

Leave a Comment