从python打开java JAR文件 [英] Opening a java JAR file from python

查看:501
本文介绍了从python打开java JAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从python中打开一个JAR文件并遇到问题。我正在使用..

  import os 
os.system(rX:\ file.jar)

它似乎打开窗口然后立即关闭,我知道我错过了一个简单的命令但是不知道它是什么,谢谢你的帮助

解决方案

你想从.jar执行代码,还是打开它? / p>

如果打开,那么 .jar 文件的格式与 .zip 文件,您可以使用 zipfile 模块来操作它。示例:

  def show_jar_classes(jar_file):
打印出来自jar_file的.class文件
zf = zipfile.ZipFile(jar_file,'r')
try:
lst = zf.infolist()
for zi in lst:
fn = zi.filename
if fn.endswith('。class'):
print(fn)
finally:
zf.close()

如果你想执行它,那么我更喜欢创建一个简单的批处理/ shell脚本,它执行 java 参数如 -Xmx 以及应用程序所需的环境设置。


I am trying to open a JAR file from python and running into problems. I am using..

import os
os.system(r"X:\file.jar")

it appears to open the window then it shuts right away, I know I am missing a simple command but not sure what it is, thanks for the help

解决方案

Do you want to execute code from .jar, or open it?

If open, then .jar file is the same format as .zip files and you can use zipfile module to manipulate it. Example:

def show_jar_classes(jar_file):
    """prints out .class files from jar_file"""
    zf = zipfile.ZipFile(jar_file, 'r')
    try:
        lst = zf.infolist()
        for zi in lst:
            fn = zi.filename
            if fn.endswith('.class'):
                print(fn)
    finally:
        zf.close()

If you want to execute it then I prefer creating simple batch/shell script which execute java with some parameters like -Xmx and with environment settings required by application.

这篇关于从python打开java JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆