Search code examples
javacompatibility

How can I have Java 5 output from Java 6 source in Eclipse?


In the project properties, in the "Java Compiler" section, there are some settings for the "JDK Compliance". I wanted to set the source compatibility to 6 and the .class files' compatibility to 5. This is apparently not allowed: I get the message "Classfile compatibility must be greater or equal than source compatibility".

Is this a limitation of Eclipse or a fundamental issue of Java version compatibility? Are there workarounds?

I would like to use Java 6 in development and for most targets, but I want to produce Java 5 compatible artifacts for some targets such as Macs. I'm fine if this means having two builds, as long as it's the same source.


Solution

  • See also this thread pointing to a similar (older) issue:
    "Java theory and practice: Using Java 5 language features in earlier JDKs":

    Unless you are using some kind of external tool to transform Java 6 bytecode into Java 1.5-compatible bytecode, you can not indeed set the class compliance to 1.5 and the source compilance to 6.0.