I have the following scenario:
Class Foo references a method in class Bar. I'd like to compile class Foo with javac targeting Java 1.7 but providing a Bar.class binary on the class path that uses Java 8 syntax and was compiled with JDK 8. In production, JRE 1.7 will be used to run my application with a different copy of Bar.class on the classpath - this version of class Bar uses Java 1.7 syntax and was built with JDK 7.
For straight javac, you can use -source/-target to let the Java8 JDK build Java7 class files (which really just means putting a different version number in the class file).
My builds use Maven, and while my Jenkins server was building with Java8, the source/target specified was 1.7 and everyone could run with their existing Java7 JDK. When the first dependent project migrated to Java8, the Maven POM changed to build 1.8 target and everyone was forced to upgrade.
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.