0

My Java JAR executes fine in linux command line, and I would like to have it executed through a python script.

I get the following error when trying Popen:

Error: Could not find or load main class jar

Any ideas?

What I've tried thus far:

  1. Command line execution of JAR file. Checked.
  2. Popen with simple java and -version. checked.
  3. Update cwd. Checked.

Working Java call:

>>> javaCall = subprocess.Popen(['java', '-version'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Failed command:

>>> javaCall = subprocess.Popen(['java', 'jar' , 
'abs/path/to/jar/abc.jar', 
'arg 1', 'arg 2', 'arg 3'], cwd = 
'/abs/path/where/jar and python files live', stdin=subprocess.PIPE, 
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output, err = javaCall.communicate()
>>> print err
Error: Could not find or load main class jar

Any pointers I'm missing?

asked Jul 31, 2017 at 21:40
3
  • Add a - in front of jar ['java', '-jar' ] Commented Jul 31, 2017 at 21:42
  • @drelliot. Lol, good catch. it did the trick. Please put it in an answer and I'll mark it. Commented Jul 31, 2017 at 21:43
  • No worries! happy to help Commented Jul 31, 2017 at 21:48

1 Answer 1

1

Missing a - in front of jar

javaCall = subprocess.Popen(['java', 'jar' , 
'abs/path/to/jar/abc.jar', 
'arg 1', 'arg 2', 'arg 3'], cwd = 
'/abs/path/where/jar and python files live', stdin=subprocess.PIPE, 
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output, err = javaCall.communicate()
>>> print err
Error: Could not find or load main class jar

Change to: javaCall = subprocess.Popen(['java', '-jar' , ~~~

answered Jul 31, 2017 at 21:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.