将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


相关文章

TensorFlow打印tensor值的实现方法

TensorFlow打印tensor值的实现方法

最近一直在用TF做CNN的图像分类,当softmax层得到预测结果后,我希望能够看到预测结果,以便和标签之间进行比较。特此补上,以便自己记忆。 我现在通过softmax层得到变量trai...

Python 查看文件的读写权限方法

实例如下: # -*- coding: utf-8 -*- # @author flynetcn import sys, os, pwd, stat, datetime; LOG_F...

Python实现读取TXT文件数据并存进内置数据库SQLite3的方法

本文实例讲述了Python实现读取TXT文件数据并存进内置数据库SQLite3的方法。分享给大家供大家参考,具体如下: 当TXT文件太大,计算机内存不够时,我们可以选择按行读取TXT文件...

Python+matplotlib实现华丽的文本框演示代码

Python+matplotlib实现华丽的文本框演示代码

华丽的文本框演示 首先看看演示结果: 实现代码 import matplotlib.pyplot as plt plt.text(0.8, 0.5, "python", size...

用Python写冒泡排序代码

python代码实现冒泡排序代码其实很简单,具体代码如下所示: 代码Code highlighting produced by Actipro CodeHighlighter (fr...