Bundling python files inside jar for access via jython

删除回忆录丶 提交于 2019-12-06 08:08:55

You can simply put test.py at the root of the jar, with the other scripts organized as they would be on the fs in normal python. Then you can do something like that:

public static void main(String[] args) {
  org.python.util.PythonInterpreter python = new org.python.util.PythonInterpreter();
  python.exec("import test");
  python.exec("test.callsomthing()");
}

the import in test.py should work as normal, including importing other modules from test.py.

Extract the python file from the jar by using the "getResourceAsStream" of the class.

See for example: http://fiji.sc/wiki/index.php/Jython_Scripting#Distributing_jython_scripts_in_a_.jar_file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!