python使用javax从Java调用Jython。脚本
我正在尝试使用Jython将一个小Python脚本集成到我的Java程序中。我似乎无法使用javax.script
包获得python/jython引擎
我从here中获取代码,并添加了一个小部分来生成以下内容:
andrew@asimov:~$ echo $CLASSPATH
/opt/jython/jython.jar:.
andrew@asimov:~$ java Engines
The following 2 scripting engines were found
Engine name: jython
Version: 2.7.0
Language: python
Engine supports the following extensions:
py
Engine has the following short names:
python
jython
=========================
Engine name: Rhino
Version: Rhino 1.7 release 4 2013 08 27
Language: ECMAScript
Engine supports the following extensions:
js
Engine has the following short names:
js
rhino
JavaScript
javascript
ECMAScript
ecmascript
=========================
python engine is null: true
js engine is null: false
andrew@asimov:~$
我添加的代码是:
String[] engineNames = new String[] {
"python", "js"
};
for (String engineName : engineNames) {
ScriptEngine engine = manager.getEngineByName(engineName);
System.out.printf("%s engine is null: %s\n", engineName, (engine == null));
}
为什么我会得到一个空的python引擎
我遇到了this bug,这似乎表明存在(或曾经存在)jython引擎。罐子在外面,但如果我能找到它,我就被绞死了
# 1 楼答案
Perthis question,使用
jython-standalone.jar
而不是jython.jar
返回非空引擎:(在我的pom.xml中,我使用了
<artifactId>jython-standalone</artifactId>
)好奇,但至少我可以继续前进