According to the documentation ( Java 5 , Java 6 ), the Oracle SDK should be able to do this by following the instructions in the cross-compilation example .
Java 6 should support any version from 1.3 to 1.6 as -target ; it says nothing about what happens when you use generics and other "compatible" functions in the source. The compiler should be able to trim them.
Another culprit in the game may be javac : the compiler can handle this set of arguments, but the command line tool may be offended.
In this case, write your own command line using the Java Compiler API . This may allow you to get some tricks that you cannot achieve otherwise.
You can also try the Eclipse compiler (see " Using the Batch Compiler ).
This may fail due to the way Java works: Java X code can run in Java Y as long as X <= Y. So, although you can easily compile Java 1.4 code for the Java 6 virtual machine, the opposite not always true.
If all else fails, write a preprocessor that reads the source code and breaks up unsupported elements (for example, @Override on interfaces). As long as you compile code with annotations once in a while using Java 6, the converted code should also be safe (if your code strip has no error ...)
Aaron Digulla Feb 13 '12 at 13:23 2012-02-13 13:23
source share