Reputation: 9501
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
Upvotes: 6
Views: 16798
Reputation: 1
For the previous question, Executing it is easy.
import os
os.system('start X:\file.jar')
Upvotes: 0
Reputation: 54342
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.
Upvotes: 10