Reputation: 16501
Will a Java 8 codebase that is compiled with Java 8 work on a Java 6 VM?
Upvotes: 2
Views: 179
Reputation: 9026
Depending on what Java 8 features the code is using, you may be able to run Retrolambda on it and use the results in a Java 6 JVM. Maybe.
Upvotes: 0
Reputation: 72636
Yes, but if you don't make use of features of java 7 and java 8 ...
If the codebase is written using features of newer java versions, then no there's no way to do it!
However, if you want to run them on java 6 you have to set java 6 compliance level(with -source 1.6 -target 1.6
javac parameters) when you compile source code files, to make them compatible with java 6. If you don't set the compliance as shown above, you will get an UnsupportedClassVersionError :
java.lang.UnsupportedClassVersionError:Unsupported major.minor version XX.X
Upvotes: 7
Reputation: 1446
It generally only works the other way around, so running a Java 6 compiled application should run on a JVM of a higher version. The other way around is not possible I'm afraid, unless you don't use any new features and tell javac
that your source version is 1.6 (i.e. -source 1.6
) which essentially means you're programming Java 6 :).
Upvotes: 2