I get the error below when trying to run an executable jar file. The file only contains a main with one line "System.out.println("Woo!");" and runs fine in eclipse.
I'm not sure how to read these error messages.
(too new to post images correctly)
The error means that you have compiled the code with a higher version of java and trying to run it on a older version of jvm.
Since it says major.minor version 51.0 it means that your compiler is java6. So you should run your program on java6 or higher.
Your compiled class is in jre 1.5 and your system default jre is different(might be 1.6).
compile your code in same version of jre.
Related
I am trying to compile and run the example java project. Instead of using the default JDK I have chosen JDK 15 by providing the setting --java_language_version="15". The complete command looks like this:
bazel run --java_language_version="15" //:ProjectRunner
I can see that it downloads Zulu JDK 15. But running the executable throws the following error:
java.lang.UnsupportedClassVersionError: com/example/ProjectRunner has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 55.0
What I already figured out is that it tries to run under JDK/JRE 11 (class file versions up to 55.0) but has been compiled with JDK 15 (class file version 59.0).
What I don't understand is why bazel runs the java application with the default JDK (11).
As you say, the --java_language_version flag only selects what JDK used to compile Java. The JRE used to execute Java may be configured with the --java_runtime_version flag. See https://bazel.build/docs/bazel-and-java#config-jvm.
When I created a Jar and compiled in windows and tried to run in Hadoop. It's throwing an error while running this script
admin1#admin1:/usr/local/hadoop/conf$ hadoop jar wordcount.jar com.shailu.wordcount.WordCount input/wordcount output/wordcount
Error is:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/shailu/wordcount/WordCount : Unsupported major.minor version 52.0
Nothing wrong with ur execution,
Looks like there is a mismatch in the compile and the execute environment.
type "java -version" in both the environments , i.e. windows and hadoop(linux/unix)
My doubt is you have compiled the code in a higher version like 1.8, change it to 1.7 or so, you should be ok.
or while compiling choose the same java version as the hadoop environment have.
I have encountered such problem. You need keep the compiler consistently between windows and hadoop or hadoop compiler higher than windows'. See picture I screenshot from Internet(contain a little Chinese, you also can refence this website if you can open it: JDK compiler version mapping minor.major). I guess JDK1.8.x is mapping major.minor version 52.0.
JDK编译器版本-------------JDK compiler version
target参数----------------target parameter
十六进制 minor.major------hexadecimal minor.major
十进制 minor.major--------decimal minor.major
不能带 target 参数--------can't add target parameter
默认为--------------------default
When my jar is run on another computer there occurs a java exception but on my setup it runs ok. They are using Java 1.8? atleast one of them is. and my JDK is also 1.8.
Could the cause of this be in META-INF? I also tried sending .class files and running the main class using cmd (it maybe gave some other error i think)
Also I've exported it as a jar from eclipse, not executable jar. Could this be the cause?
EDIT
One of the stacktraces says: "Unsupported major.minor version 52.0"
Java version mismatch. The other computer not really running with JRE 8.
See this answer for detail Unsupported major.minor version 52.0
Your code was compiled with Java Version 1.8 while it is being executed with Java Version 1.7 or below.
I just recently recovered some programs from my old hard drive, so I tried compiling one and running it, and I get this error in command prompt:
Unsupported major.minor version 52.0
I compiled the program with Java 8, and I ran it with Java 8. The only thing I can think of is the fact that I used Java 7 with the program on my old computer. Also, I'm using Windows XP on this new computer, while I used Windows 7 on the old computer.
I am using two libraries, but I don't think that is the issue since the program ran fine in NetBeans.
Any ideas of what the problem is?
Based on your comment to archetype's answer, my guess is that java 7 is in one of your windows directories, like C:\Windows\System32 and that directory is before your JAVA_HOME directory in your path. Try typing 'where java' on the CMD. If it's in more than one directory, see which one comes first in your PATH variable and look at the version of java in that directory.
The root cause of the problem is that, the code was compiled in later version but your default runtime is running on the lower version. you can do this by simply checking your current version. java -version and javac -version. You may need to check the Java from the Control Panel. To verify the actual version of your JAR file, you may need to extract the actual version and look for the version information
javap -verbose <Java_Class_Name> | findstr "major"
I have created a Java Swing application in eclipse. And I have packaged the application into Runnable JAR with the help of Eclipse Export functionality. But I am unable to run the JAR in other machines. In my system it is working fine.
How to make it independent?
The default output folder(i.e for class files) : Project_Name/bin
The JRE is present in the C:/Programfiles/java/jre7
I have a sqljdbc Jar which is placed in the lib folder of the Project in my D drive.
I am using the option "Package Required libraries into generated JAR" but still I think the JAR is not able to fine the correct libraries when I am double clicking on teh JAR in a different machine.
Please suggest. Thanks for all your help.
I am getting UnsupportedClassVersionError in the cmd when I am trying to run the JAR through cmd in other machines
This means that you are using a lower version of the JRE than the JDK which you used to compile the sources (for example, sources compiled with JDK7 can not be executed by a Java 6 or lower JRE since the class file format and hence the class version has changed).
I am also getting unsupported major.minor version 51.0
51.0 is the class file version of JDK 7. Again, this indicates that you try to run your code with Java version 6 or lower.
To verify, check with
C:> java -version
which java version is actually used by default.
To fix this issue, use an absolute path to the java version you require, like
C:> C:\Programfiles\java\jre7\bin\java -jar myapplication.jar