I was considering if a java project could produce 2 jars: one for java7 and one for java6, yes, the source code might use some some java7 new features.
so to generate the java6 jar, the command line would be like:
javac -target 1.6 -bootclasspath jdk1.6.0\lib\rt.jar -extdirs "" MyApp.java
Unfortunately, It simply emits an error:
javac: target release 1.6 conflicts with default source release 1.7
According to this document, it should be possible for jdk6 vs jdk5, anybody knows why it doesn't work in jdk7 vs jdk6? did I do something wrong, or is it just officially not supported?
Thanks.
AFAIK, the source and target have to be the same. Even for Java 6. The only exception is the source can be 1.1 and the target 1.0.
Given there is little difference in the JVM between the latest JVM for Java 6 and Java 7, I suggest you consider upgrading. Also Java 6 will be, End Of (free) Service in Nov 2012, which three months from now...
Even if it were possible it's generally a bad idea - if you want to be sure your code will work on java 6 then you have to build it on java 6. Each new version of java introduces new classes in the class library, and adds new methods to existing classes, and even if you set your java 7 compiler to generate 6-compatible bytecode it won't catch cases where you call a 7-only method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With