How to use latest Java version

This is a note for developers aiming to use the latest Java features.
There will be always a latest version of Java that brings new features but not everybody has it installed yet. The compile Ant target, however, must guarantee that everybody is able to compile jMoby - at least the classes that are for his/her version of Java.

Here is how to do it (assuming the latest version is 1.6):

First to say is that it was put there as a working solution for those who really need to use 1.6. Any new class that needs 1.6 must be explicitly named in the build.xml file in the property version.excludes (the property is actually in a separate fragment in xmls/exceptions.xml).

Having said that please note that nothing prevents you to use Java 1.6 to compile all existing (old, current) classes. That should work fine (with perhaps few semantic warnings). The previous (and the next) paragraphs are for those adding sources that can be compiled only with Java 1.6.

If you are using regular javac compiler you do not need to do anything special. The Ant will sniff around and find what java version you are using and depending on the result it will compile always all classes not mentioned as specific for 1.6, and then - only if you use Java 1.6 - it compiles additionally those new bastards. Which means that when you are using Java < 1.6, the new classes will not compiled so you will not be able to use them. But that's obvious - you cannot shop with the old Deutches Marks anymore without having new Euros, can you?

This paragraphs may not be valid for Java 1.6. It's too early to say.

If you are using jikes (which I strongly recommend because it is much much faster compiler, but that's another story) and have Java < 1.5 on your path, again nothing needs to be done. However, if you are using jikes and have Java 1.6 on your path, jikes will try to compile also the new classes and fails. Therefore, for this case you need to instruct Ant that - eventhough the Java 1.6 is available - you do not want it. Do it with by setting property java.latest.version to false. Either (recommended) put the line:

   java.latest.version = false
in your build.property file, or use it on the Ant's command line:
   ant -Djava.latest.version=false compile

Martin Senger
Last modified: Thu Feb 14 15:01:34 2008