Ant using a lower version of Java than the system&

2019-03-01 10:54发布

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?

标签: java ant
3条回答
Viruses.
2楼-- · 2019-03-01 11:12

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.

查看更多
Anthone
3楼-- · 2019-03-01 11:16

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.

查看更多
够拽才男人
4楼-- · 2019-03-01 11:18

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

查看更多
登录 后发表回答