I hava class compiled using jdk7 and I am trying to invoke using JDK6 and the jars in classpath are compiled using jdk 6
jdk6/bin/java com.test.myclass -classpath abc.jar xyz.jar pqr.jar MNO.jar
my class com.test.myclass
is present in MNO.jar
and abc.jar xyz.jar pqr.jar
are compiled with jdk6
with jdk7 it works
jdk7/bin/java com.test.myclass -classpath abc.jar xyz.jar pqr.jar MNO.jar
This also fails.Any input to solve this problem.?
Exception in thread "Main Thread" java.lang.UnsupportedClassVersionError: com/test/MyClass: unsupported classversion 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.test.MyClass. Program will exit.
256
Thanks
When you compile the sources, give the parameter -target 1.6
. That way 1.6 compliant bytecode will be generated (ie class files will indicate that they need 1.6 or higher to run).
As the last resort you can change the class version at .class file from 33 to 32 (7-th byte from the file beginning) with a hex editor. If the class does not use any Java 7 new feature it will work OK.
如果您在类中使用了任何特定于jdk 7的代码,则它将无法正常运行,否则它将正常运行。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.