tags:

views:

114

answers:

2

here is my scenario:

  • workstation A : Sun JDK 1.6
  • workstation B : Sun JDK 1.5

I build on A and B with Ant 1.7

<javac srcdir="${foo}" destdir="${bar}" source="1.5" target="1.5">
  <include name="**/*.java"/>
  <exclude name="**/test/**/*.java"/>
</javac>

yet the .class files are different size on A & B, let alone CRC. is it supposed to be this way? or am I missing something obvious?

+5  A: 

Yes, it is supposed to be that way. Even when targeting the same VM, different compilers might emit different byte code. As long as the resulting program behaves correctly, the JLS doesn't mandate precisely how source code is compiled to byte code.

erickson
+5  A: 

While you might explicitly set source="1.5" and target="1.5", this does not control which JDK version of the javac compiler you are running.

So, on the workstation with JAVA_HOME/PATH pointing to JDK 1.6, you have class files built on a 1.6 javac which should be compatible with a 1.5 JRE.

However, the source="1.5" and target="1.5" only specify the compatibility of the syntax/language features; if you are relying on some classes available only in the 1.6 JRE, then you will not get any compiler warning here when using source="1.5" and target="1.5" on a 1.6 javac.

To address this last point, you need to tell the <javac> Ant task to use a different bootclasspath.

matt b
+1 - not for the answer, but for the useful tip (hadn't thought of that)
Steve B.
It's a pretty lame workaround - it'd be far easier to just use the correct indented jdk
matt b