I'm trying to call Jython from a Java 6 application using javax.script
:
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class jythonEx
{
public static void main (String args[]) throws ScriptException
{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine pyEngine = mgr.getEngineByName("python");
try {
pyEngine.eval("print \"Python - Hello, world!\"");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
This is causing a NullPointerException:
java.lang.NullPointerException
at jythonEx.main(jythonEx.java:12)
Does anyone have any idea what I'm doing wrong here?
Edit:
Thanks for the responses! I added jython.jar to the classpath and it runs properly:
java -cp "./;jython.jar" jythonEx
You'd probably have to register a ScriptEngineFactory for'python'
You have to register your engine first.
From: ScriptEngineManager.getEngineByName:
The user guide says to use it with JSR-223 you have to:
Did you do that already?EDIT About your comment: I think you should open a new question, you'll get better answers.