问题
I am trying to run some Java code using PuTTY. I have all the jar files I need in a folder and when in the folder with the 'classname.class' folder I try to run the file but I get the following error.
Exception in thread "main" java.lang.UnsupportedClassVersionError: dueDate (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:489)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:104)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:245)
at java.net.URLClassLoader.access$1(URLClassLoader.java:211)
at java.net.URLClassLoader$1.run(URLClassLoader.java:192)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:290)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)
I don't know what this error means and how I should go about fixing it. I used Eclipse to program it and jdk-6u14
.
PuTTY is using Java version '1.2.2'
How do you cange it to use a newer version of Java?
回答1:
Well it's not really PuTTY that's using Java. It's the server you're connecting to. PuTTY is just what you're using to conenct to that server.
You have two options:
- Change the target version of Java (Windows/Preferences/Java/Compiler/Compiler Compliance Level) to 1.3... ideally you should compile against a 1.2.2 JDK as well, in order to avoid using any classes which won't be present on the server.
- Get hold of a more up-to-date version of Java on the server.
The latter is likely to be harder but much better. You really don't want to have to restrict yourself to Java 1.2.2.
回答2:
You're trying to run new java code on a really old JDK - 1.2.2
Eclipse might provide some backwards-compilation options (check your project -> preferences -> java compiler), though I think it only goes back to 1.3.
Therefore you might want to try using a newer JDK to actually run the code.
回答3:
The error suggests that you are trying to run classes on a JVM that does not support them. The class version 49.0 was introduced in Java 5. JREs before that version will not support them.
回答4:
UnsupportedClassVersion means the compiled class was compiled with a later version of the JVM than you're trying to run it with. The last few major versions are java 1.6==50.0, java1.5==49.0, java1.4==48.0.
BTW, you can set eclipse to compile an earlier version of the class, although I'm not sure you can go back as far as 1.22- Project:Properties:Compiler:CompilerComplianceLevel.
回答5:
It basically means you are trying to run code that is using features that are not supported on that version of the JVM. Your server has an older JVM version than what you are using in your eclipse. Try upgrading your server JVM to the most up to date version possible.
回答6:
I was having the same issue earlier when I was trying to use command
java -jar <jarfilename> --http <portname> --id <id name>
to run and demonstrate a DHT standalone projects. The issue is with the EC2 instances settings and it resides in JAVA version. So all you need to do is to update the version. I can't believe that there could be such difference in two close updates, but the command doesn't work in JAVA1.7 and hence I updated it to JAVA 1.8. Run these commands to do the following removing and installing new version
sudo yum install java-1.8.0
and then
sudo yum remove java-1.7.0-openjdk
Remember first install version 1.8 and then remove 1.7. And then i hope your issue would be resolved
来源:https://stackoverflow.com/questions/1200422/unsupportedclassversionerror