6

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

1
  • 2
    what are you trying to accomplish? Commented Nov 4, 2011 at 6:26

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Still can't get this to appear open and nothin
Adam, you must answer you very important question: what I want to do with this .jar file? Execute? Show content? Add some new file? This answer shows how to open .jar and show its content, other answer shows you how to execute such file. Those two answers shows the most useful operations for .jar.
0

For the previous question, Executing it is easy.

import os os.system('start X:\file.jar')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.