使用javax.scripting实现从Java调用Jython

2024-06-13 12:18:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用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:~$

我添加的代码是:

^{pr2}$

为什么我得到一个空的python引擎?在

我遇到了this bug,这似乎表明存在(或曾经)一个jython-引擎.jar在外面,但如果我能找到它,我就被绞死了。在


Tags: the代码name引擎versionjsextensionsjython
1条回答
网友
1楼 · 发布于 2024-06-13 12:18:09

对于this question,使用jython-standalone.jar而不是jython.jar返回一个非空引擎:

andrew@asimov:~$ export CLASSPATH=jython-standalone-2.7.0.jar:.
andrew@asimov:~$ java Engines | tail -11
Engine name: jython
    Version: 2.7.0
    Language: python
    Engine supports the following extensions:
            py
    Engine has the following short names:
            python
            jython
=========================
python engine is null: false
javascript engine is null: false
andrew@asimov:~$

(在我的pom.xml文件,我使用了<artifactId>jython-standalone</artifactId>

很好奇,但至少我可以继续。在

相关问题 更多 >