pavi
pavi

Reputation: 674

Ant using a lower version of Java than the system's Java version

This behaviour appeared strange me. The following is what happened:

  1. We have a build.xml file for Ant, which says <javac source="1.5" target="1.5"></javac>.
  2. We have updated Java on our system (Linux) to 1.6, but we forgot to update the Ant build.xml file.
  3. Ant building is happening successfully, How is it happening? Is it like the higher version of Java can downgrade to lower versions? Or if Ant cannot find the version of Java specified it uses the default version?

Upvotes: 1

Views: 1138

Answers (3)

Naveen Ramawat
Naveen Ramawat

Reputation: 1445

It will generate the byte code of JDK 1.5 instead of JDK 1.6, because Java supports backward compatibility so byte code of JDK 1.5 could easily run on JDK 1.6 JRE.

Upvotes: 0

Keerthivasan
Keerthivasan

Reputation: 12880

There will not be any problem in upgrading JDK in this scenario

<javac source="1.5" target="1.5"></javac>

Means that it tells Java compiler that source is written using Java 1.5 and it should create the target build suitable for Java SE 1.5 environment.This is really possible with newer JDK.This is exactly the same as

javac -source 1.5 -target 1.5

Please refer the documentation of the javac tool

Hope this helps

Upvotes: 1

Henry
Henry

Reputation: 43728

These options are passed on to the Java compiler. It can generate byte code for older JVMs (target) and it can also accept source written for older Java versions (source). This makes for example sense, when a new Java version introduces new keywords but you use that word as identifier in your source.

Upvotes: 1

Related Questions