This post originated from an RSS feed registered with Java Buzz
by Vlad Roubtsov.
Original Post: A case for cross-compilation
Feed Title: Java Curiosity Shop
Feed URL: http://www.blog-city.com/bc/
Feed Description: Java esoterics: things from "don't try this at home" category
Here is an article on a very rarely discussed topic. Using correct -target and -bootstrap compiler options is not hard and yet few people or even enterprise software houses seem to do it, which I find quite odd. In any case, if you wanted to really understand how javac locates class definitions or what those "Compliance and Classfiles" Eclipse compiler options are really about, the article might prove interesting.
As explained in the article, with a small effort you can control which Java platform versions your code is allowed to run on. This is in effect a partial solution to the Java versioning problem. It is kind of unfortunate that Java does not have a better one at the moment. It would have been great to be able to look at a .class file and detect programmatically which J2SE platforms it is compatible with. I hope the new metadata support coming in J2SE 1.5 will help in this area.
I got the idea for my opening puzzle from an ADVANCED-JAVA discussion started by Attila Szegedi. He tells me that his example has already been used to convince JDOM people to build against 1.2.2 rt.jar. Also, I like the compiler in Eclipse a lot and have submitted a feature request for the compiler to warn you when you are using a target setting that is incompatible with the JRE library version. Looks like it will be supported as a new compiler warning in Eclipse 3.0. Hopefully, cross-compilation will become a common practice one day.