3

Possible Duplicate:
Override the compiler attribute in an Ant javac task

In Ant, how exactly do I use the build.compiler option, or the <javac> task's compiler attribute?

I tried setting compiler="javac1.5", but when I opened the resulting class-file in a hex editor, the class version was still shown as 32 hex (version 1.6) — until I set JAVA_HOME to point to my JDK 1.5 installation. (Until then, it had been pointing to my JDK 1.6 installation.) So it seems like JAVA_HOME supersedes the compiler attribute — in which case, what is the purpose of that attribute?

The source and target attributes do seem to work correctly; when I specify the target version, the resulting class-file does have the right version.

Community
  • 1
  • 1
JKV
  • 267
  • 4
  • 13

1 Answers1

6

The purpose of the attribute is to be able to choose something like gcj or jikes instead of the standard JDK compiler. javac1.5 (and javac1.6 etc.) is just an alias for modern, the standard compiler, and is defined simply to support the rule that the default value of build.compiler is javac1.x with x matching the running JDK (so the default is modern on 1.3 and higher and classic on 1.2 and below).

If you want to compile classes that will run on 1.5 then you need to use source="1.5" target="1.5" and also set the bootstrap classpath to point to a 1.5 class library, to ensure you aren't calling methods that were introduced in 1.6 or later.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • I sense the asker wanted to know how to set and where to set the build.compiler property. This is because there are several references across the internet to build.properties but I have found nowhere which explains how to use build.properties. Indeed, this is what has brought me to this question. For this reason also, I do not feel this question is a duplicate! My guess at the answer is to use the ant task something like this: . Am I correct? As this question has been marked as a duplicate, I cannot offer my answer. – IqbalHamid Jul 17 '18 at 11:25