同样的我们需要安装jython,具体的步骤如下:

1. 去 http://sourceforge.net/projects/jython/ 下载最新的jython相关的jar包。

2. 下载下来的jar包其实既是使用的时候需要引入的jar包,也是安装就jython的jar包。具体安装细节参照:https://wiki.python.org/jython/InstallationInstructions#jython-2-7-0

其实直接使用: java -jar jython_installer-2.5.2.jar 就可以根据界面指导进行安装。

3. 如果我们现在想在java中调用python代码或者执行python文件,我们只需引入jypthon安装目录下的jython.jar即可。(这一点和jruby的使用方式类似)

 

调用的代码示例如下:

1 PythonInterpreter interpreter = new PythonInterpreter();  
2 interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");  
3 interpreter.exec("print days[1];"); 
JavaCallPython

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-12-06
  • 2021-05-17
  • 2021-12-03
猜你喜欢
  • 2021-12-05
  • 2021-05-14
  • 2022-12-23
  • 2021-12-05
  • 2021-12-05
  • 2022-03-07
  • 2021-07-17
相关资源
相似解决方案