在用jython调用python脚本时出现的问题:
ERROR 4208 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is SyntaxError] with root cause
org.python.core.PyException: null
下面是Java里调用部分的代码:
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("E:\\test\\mypro.py");
PyFunction pyFunction = interpreter.get("mypro", PyFunction.class);
PyObject pyobj = pyFunction.__call__();
System.out.println("the anwser is: " + pyobj);
mypro.py里的mypro这个函数不需要参数,但是有返回字符串,不知道哪里出问题了。
PythonInterpreter interpreter = new PythonInterpreter();
try {
interpreter.execfile("E:\\test\\mypro.py");
PyFunction pyFunction = interpreter.get("mypro", PyFunction.class);
PyObject pyobj = pyFunction.__call__();
System.out.println("the anwser is: " + pyobj);
} catch (PyException e) {
System.out.println("Python error: " + e.toString());
e.printStackTrace();
}