将Python代码打包为jar软件的简单方法

yipeiwu_com6年前Python基础

py 写东西快
但是java 生态广
比如大数据 py 虽然好 但是利用不到java的整个的生态的代码

scala 虽然也好但是毕竟 有些库 需要自己写的多
虽然也很简单 ,但是查文档也很麻烦

那么 问题来了
最简单的的方式就是直接把py 打包 jar

那么 问题又来了 py 打包成java 挺麻烦的 官方文档看不懂

答案 有了
写了个 包 https://github.com/yishenggudou/jythontools
搞这个事情

timger-mac:test timger$ python ../jytool/jytoollib.py hellojython.py main 

timger-mac:test timger$ java -jar output.jython.jar 
*sys-package-mgr*: processing modified jar, '/Users/timger/GitHub/jythontools/jytool/test/output.jython.jar'
hello jython
timger-mac:test timger$ 

整体代码如下

timger-mac:test timger$ java -jar output.jython.jar a a s s s
hello jython
['a', 'a', 's', 's', 's']
timger-mac:test timger$ cat hellojython.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2011 timger
#  +Author timger
#  +Gtalk&Email yishenggudou@gmail.com
#  +Msn yishenggudou@msn.cn
#  +Weibo @timger http://t.sina.com/zhanghaibo
#  +twitter @yishenggudou http://twitter.com/yishenggudou
#  Licensed under the MIT License, Version 2.0 (the "License");
__author__ = 'timger'
import sys


def main():
  print "hello jython"
  print sys.argv


相关文章

Selenium chrome配置代理Python版的方法

环境: windows 7 + Python 3.5.2 + Selenium 3.4.2 + Chrome Driver 2.29 + Chrome 58.0.3029.110 (64...

python实现数独算法实例

本文实例讲述了python实现数独算法的方法。分享给大家供大家参考。具体如下: # -*- coding: utf-8 -*- ''' Created on 2012-10-5 @a...

解析PyCharm Python运行权限问题

解析PyCharm Python运行权限问题

先通过 which python 获得 python 指令所在路径: $ which python /usr/bin/python 如上得到了其所在路径是 /usr/bin/pyt...

利用 Flask 动态展示 Pyecharts 图表数据方法小结

利用 Flask 动态展示 Pyecharts 图表数据方法小结

本文将介绍如何在 web 框架 Flask 中使用可视化工具 pyecharts, 看完本教程你将掌握几种动态展示可视化数据的方法,不会的话你来找我呀... Flask 模板渲染 1....

Python 中urls.py:URL dispatcher(路由配置文件)详解

Python 中urls.py:URL dispatcher(路由配置文件)详解

urls.py:URL dispatcher(路由配置文件) URL配置(URLconf)就像是Django所支撑网站的目录。它的本质是URL模式以及要为该URL模式调用的视图函数之间的...