我试图在一个使用javax.script
的Java 6应用程序中调用Jython:
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();
}
}
}
这会导致空指针异常:
java.lang.NullPointerException
at jythonEx.main(jythonEx.java:12)
有人知道我在这里做错了什么吗?
编辑:
感谢回复!我将jython.jar添加到类路径中,现在可以正常运行:
java -cp "./;jython.jar" jythonEx