I am creating a python program that runs a jar file. The jar file and some support files are placed in a different location than the python program's directory. I tried adding jar file path to sys.path
but it's unable to access the file from there, however the path is added to sys.path
correctly. How can I get this working?
jar file location: E:\data
python file location: C:\Users\user\Desktop
I am using subprocess
to call the jar file, the code looks like:
import os
import sys
import subprocess as sp
class abc():
def __init__(self):
sys.path.append(r'E:\data')
def run(self):
print sys.path
env = dict(os.environ)
env['JAVA_OPTS'] = '-Xms256m -Xmx256m -Xss1024k'
sp.call(['java', '-jar', 'file.jar'], env=env)
if __name__ == '__main__':
o = abc()
o.run()
After running above code, I get an error saying:
Error: Unable to access jarfile file.jar