1
我正在嘗試使用Jython將一個小Python腳本集成到我擁有的Java程序中。我似乎無法使用javax.script
軟件包獲取python/jython引擎。使用javax.scripting從Java進行Jython調用
我從here代碼加入少量生產這樣的:
[email protected]:~$ echo $CLASSPATH
/opt/jython/jython.jar:.
[email protected]:~$ 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
[email protected]:~$
我添加的代碼是:
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));
}
爲什麼我收到一個空蟒蛇引擎?
我跑過this bug,這似乎表明有(或有)jython-engine.jar在那裏,但如果我能找到它,我會被絞死。
嘗試'「py」'而不是'「python」'。 –
@ElliottFrisch同樣的結果,如果我使用「py」作爲名稱。我也試過'manager.getEngineByExtension(「py」)'無濟於事。 – Andrew
您使用的是什麼版本的'java'? –