我正在使用jython库(jython-standalone-2.7-b3)从Java执行python脚本。我唯一的目的是能够从我的java代码中触发和执行python脚本文件。我能够正确地编写独立的主类,事情进展顺利。现在我将相同的代码放在我的应用程序中(在我的应用程序服务器中),现在对于相同的脚本,我在每个阶段都会遇到错误。它说一些模块找不到等等。但是当我从主类再次尝试时,相同的代码和脚本执行得很好。是否有任何运行环境必须注入以使其运行..
使用的代码段
public void executeScript(String inputFile, String outputFile) throws FileNotFoundException {
final PythonInterpreter inter = new PythonInterpreter(null, new PySystemState());
Writer writer = null;
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile)));
inter.setOut(writer);
inter.execfile(inputFile);
}
我得到的例外是
File "/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/posixpath.py", line 392, in normpath
AttributeError:' NoneType'对象没有属性' startswith'
at org.python.core.Py.AttributeError(Py.java:177)
at org.python.core.PyObject.noAttributeError(PyObject.java:946)
at org.python.core.PyObject.__getattr__(PyObject.java:941)
at posixpath$py.normpath$27(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/posixpath.py:412)
at posixpath$py.call_function(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/posixpath.py)
at org.python.core.PyTableCode.call(PyTableCode.java:166)
at org.python.core.PyBaseCode.call(PyBaseCode.java:137)
at org.python.core.PyFunction.__call__(PyFunction.java:347)
at sysconfig$py.f$0(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/sysconfig.py:712)
at sysconfig$py.call_function(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/sysconfig.py)
at org.python.core.PyTableCode.call(PyTableCode.java:166)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.imp.createFromCode(imp.java:393)
at org.python.core.util.importer.importer_load_module(importer.java:109)
at org.python.modules.zipimport.zipimporter.zipimporter_load_module(zipimporter.java:161)
at org.python.modules.zipimport.zipimporter$zipimporter_load_module_exposer.__call__(Unknown Source)
at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:47)
at org.python.core.imp.loadFromLoader(imp.java:520)
at org.python.core.imp.loadFromLoader(imp.java:520)
请帮助..