My project is build in 1.4.2 JDK. Now it is going to interact with a third party jar, build in JDK 1.6
I am getting compatibility problem while using client classes. Is开发者_StackOverflow社区 it possible to resolve it without upgrading my JDK to 1.6 or rebuilding third party jar in 1.4.2
You cannot run a class compiled with JDK 1.6 on previous JDK 1.4 because you will got an java.lang.UnsupportedClassVersionError
exception. This is due to Java is not forward compatible, it is just backward compatible (see specification).
In order to verify it I have installed JDK 1.4.2.19 and JDK 1.6.0.23 and wrote a sample application:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world!"); } }
Built it with JDK 1.6.0.23:
../1.6.0.23/bin/javac HelloWorld.java
And run it with JDK 1.4.2.19:
../1.4.2.19/bin/java HelloWorld
Output:
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld (Unsupported major.minor version 50.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:539) ...
Solution: You may try to rebuild your third party application with JDK 1.4 if it doesn't call methods introduced in 1.6 (and 1.5).
精彩评论