Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 780
Hanno Fietz Avatar asked Mar 19 '26 09:03

Hanno Fietz


2 Answers

As Eclipse says, you can't generate java5 class files from java6 source, it's just not an option. If you need to generate java5 builds, you need to use java5 source level.

Do you really need to use Java6 source level? If there are things in the Java6 API that you need to use, then generating builds for Java5 won't work when you try and run those builds. If you don't need to use Java6 API, then you don't need to use Java6 source compatibility either.

like image 54
skaffman Avatar answered Mar 20 '26 23:03

skaffman


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.

like image 29
VonC Avatar answered Mar 20 '26 23:03

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!