jython运行python文件
环境:
java:
[root@node2 ~]# java -version java version "1.8.0_261" Java(TM) SE Runtime Environment (build 1.8.0_261-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
python:
[root@node2 ~]# python Python 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2 pe "help", "copyright", "credits" or "license" for more information. >>>
本次测试脚本:
test.py
import sys; def pri(f1,f2): print "This "+f1+" done." print "this "+f2+" done." if __name__ == '__main__': f1=sys.argv[1]; f2=sys.argv[2]; pri(f1,f2);
python执行效果:
[root@node2 ~]# python test.py aa bb This aa done. this bb done.
aa和bb 是向test.py脚本里传入的两个参数。
Jython执行效果:
分别用两个版本的jar包来测试,输出同样结果。
[root@node2 ~]# java -jar jython-standalone-2.5.3.jar ~/test.py aa bb This aa done. this bb done. [root@node2 ~]# java -jar jython-standalone-2.7.2.jar ~/test.py aa bb This aa done. this bb done.
~/test.py文件路径根据你具体情况修改。
jython-standalone-2.7.2.jar包可以到jython官网上下载,
网址:https://www.jython.org/download
https://repo1.maven.org/maven2/org/python/jython-standalone/2.7.2/jython-standalone-2.7.2.jar