1

I want to call a runnable jar file from a python script, but get 'Unsupported major.minor version 51.0' as an error in the console.

I've tried running it via os and subprocess but get the same error:

#!/usr/bin/python2.4

import subprocess
import os

os.system("java -jar parser.jar C:\folder\file.csv")

subprocess.call(['java', '-jar', 'parser.jar', 'C:\folder\file.csv'])



This is not a file path question, as the same error occurs when I put all my files in the same folder:

os.system("java -jar parser.jar file.csv")
  • 1
    What happens if you try the same command from the command line? Also, backslashes in strings need to be escaped if you want a literal backslash in your string. – user2357112 Sep 19 '14 at 18:28
  • Can you run the command successfully from the terminal? This sounds like it is a [pure Java problem](http://stackoverflow.com/questions/10382929/unsupported-major-minor-version-51-0) – unholysampler Sep 19 '14 at 18:29
  • 1
    The entire problem here is that `\f` is an escape sequence (0x0c, or form-feed). Use forward slashes, raw string literals, or escaped (doubled) backslashes. (Not adding an answer because I'm sure this is a dup, I just need to find it…) – abarnert Sep 19 '14 at 18:33
  • @abarnert While that is *an* error in this code, the error message the OP is getting is not coming from Python. The JVM isn't getting far enough to even try to use the passed in file path. An incorrect file path would likely result in a `FileNotFoundException`. – unholysampler Sep 19 '14 at 19:27
  • if i run the command from a terminal, java -jar parser.jar 'C:\folder\file.csv, it works successfully. –  Sep 19 '14 at 20:12
  • i've also tried a few variations based on these comments, but none work yet. here's my latest try: os.system("java -jar move/scripts/parser.jar C:/path/to/file/file.csv") –  Sep 19 '14 at 20:18
  • @abarnert i've also put everything in the same directory, to avoid having any slashes: os.system("java -jar parser.jar file.csv"). this also throws the same error –  Sep 19 '14 at 20:20
  • What version of the JDK was the jar compiled with? What version of Java are you trying to run with? Are there multiple version of Java installed on this machine? – unholysampler Sep 19 '14 at 20:29
  • i'm running a windows machine, which has Java 1.6 and 1.7 on it. i created the JAR using eclipse > File > export commands to create a runnable JAR. I assume it's using 1.6 to compile it (java -version shows the 1.6) –  Sep 19 '14 at 20:39
  • @privateducky Code compiled for 7 cannot be run on 6 ([Source](http://www.oracle.com/technetwork/java/javase/compatibility-417013.html)). Eclipse can be configured to compile any JDK you have installed and run on any JRE you have installed. It is possible that Eclipse is configured to compile/run on 7 but your environment path is set to 6. – unholysampler Sep 22 '14 at 13:06

0 Answers0