Search code examples
javaeclipsejavac

Is setting eclipse java compiler compliance level 1.6 same as compile using JDK 1.6?


I'm trying to consume a third-party API, where I get support for the third party API upto JDK 1.6.

I have other few projects which are built using JDK 1.7 and as part of the product I'm also packaging JRE 1.7.

if compiler compliance level is set to JDK 1.6, compile & run using JDK 1.7 libraries produce same result as of compile & run using JDK 1.6?

Would it be safe to claim support from third-party vendor when compiler compliance level is set to JDK 1.6.

Update: I presumed that setting compiler level in eclipse is same as setting -source & -target options of javac.

I'm not sure if compiling using JDK 1.7 setting source & target to 6/1.6 is same as compiling in jdk1.6.


Solution

  • You can actually specify the .class files version compatibility in the "Preferences->Java->Compiler" (project specific), so at worst you are benefitting from a more recent compiler building probably exactly the same bytecode as using JDK 1.6.

    "Compliance 1.6" however does not ensure that you get exactly the same result as using JDK1.6, but java standard ensures applications built with 1.6 will run the same on a >= 1.6 JRE.

    So if you are really afraid of incompatibilities, build the project (on your CI server I suppose) with a project specific setting 1.6 on a machine with both JRE 1.6 for this one, and 1.7 for other projects, and bundle a 1.7 in your distribution, it is guaranteed to run ok by Sun/oracle/java.

    i.e. if the code is built with JDK 1.6, and used by other JDK >= 1.7 code you are fine with respect to versioning. Probably this is the case of many jars you use everyday.

    However, building the code that is stamped 1.6, with a real JDK 1.6 is the only sensible thing to do if you are afraid of real world problems (money involved).

    So I think then you are safe to "claim support", build in 1.6 and use the jar in 1.7.