How to invoke a java program with classpath from Python 3.x

Keywords: java python-3.x executable-jar


I am trying to execute an external java program from a python 3.7 program using the java command with classpath. I am using subprocess.Popen module in Python. Somehow I am not able to get it working! Appreciate any assistance!

cmd = ['java',
           '-classpath', 'C:/Users/Documents/MqTransfer.jar', 'C:/Users/Documents/',
           'C:/Users/Documents/', 'C:/Users/Documents/',
           'C:/Users/Documents/', 'C:/Users/Documents/',
           'C:/Users/Documents/connector.jar', 'C:/Users/Documents/xerces.jar',
           'MyMqTransfer', 'C:/Users/Documents/']
    jproc = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE)
    output, errors = jproc.communicate()
    print(output, errors)

I am getting the below error

b'' b'Error: Could not find or load main class\r\n'