The solution to this problem is to download the files JavaBridge.jar
, php-script.jar
and php-servlet.jar
from http://php-java-bridge.sourceforge.net/pjb/download.php then import them into your class:
import javax.script.*;
import php.java.bridge.*;
import php.java.script.*;
import php.java.servlet.*;
Then the code can then be run as before:
String code="echo 5+5;"; //sample bit of code
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("php");
try {
engine.eval(code);
} catch (ScriptException ex) {
//catch statement
}