将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


相关文章

python3 读取Excel表格中的数据

需要先安装openpyxl库 通过pip命令安装: pip install openpyxl 源码如下: #!/usr/bin/python3 #-*- coding:utf-8 -...

简介Python中用于处理字符串的center()方法

 center()方法返回集中在长度宽度的字符串。填充是通过使用specifiedfillchar。默认填充字符是一个空格。 语法 以下是center()方法的语法: st...

对python中if语句的真假判断实例详解

说明 在python中,if作为条件语句,当if后面的条件参数为真时,则执行后面的语句块,反之跳过,为了深入理解if语句,我们需要知道if语句的真假判断方式。 示例 在python交互器...

Python获取当前脚本文件夹(Script)的绝对路径方法代码

Python脚本有一个毛病,当使用相对路径时,被另一个不同目录下的py文件中导入时,会报找不到对应文件的问题。感觉是当前工作目录变成了导入py文件当前目录。如果你有配置文件的读取操作,然...

Python如何优雅获取本机IP方法

见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 #!/usr/bin/env python # -*- coding: utf-...