I am attempting to run Python code on a Coldfusion server using Java. I am familiar with CFML but an absolute beginner with Java.
I can instantiate the objects and list their methods ok, however I am getting stuck with different object types.
The example I am trying to get to work in Coldfusion is
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class JSR223 {
public static void main(String[] args) throws ScriptException {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
engine.eval("import sys");
engine.eval("print sys");
engine.put("a", 42);
engine.eval("print a");
engine.eval("x = 2 + 2");
Object x = engine.get("x");
System.out.println("x: " + x);
}
}
What I have so far in CFML
ScriptEngine = CreateObject("java", "javax.script.ScriptEngine");
ScriptEngineManager = CreateObject("java", "javax.script.ScriptEngineManager");
ScriptException = CreateObject("java", "javax.script.ScriptException");
The part I am stuck on
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
How can I create that in CFML?
Edit:
engine = ScriptEngineManager.getEngineByName("python");
writeDump(engine);
Gives me an error: variable [ENGINE] doesn't exist
How does the other class, ScriptEngine fit in with this?
Update
I can load other Python classes so I think that the jar is installed correctly. ie with the following code I can dump the interp object.
interp = CreateObject("java", "org.python.util.PythonInterpreter");
However even then calling a method gives me this error
java.lang.NullPointerException