Can standard Sun javac do incremental compiling?

前端 未结 4 710
小鲜肉
小鲜肉 2020-12-14 01:01

Recently I started to use Eclipse\'s java compiler, because it is significantly faster than standard javac. I was told that it\'s faster because it performs incremental comp

4条回答
  •  暖寄归人
    2020-12-14 01:59

    Is it true that Sun's compiler always compiles every source file and Eclipse's compiler compile only changed files and those that are affected by such a change?

    I believe that you are correct on both counts.

    You can of course force Eclipse to recompile everything.

    But the other part of the equation is that Java build tools like Ant and Maven are capable of only compiling classes that have changed, and their tree of dependent classes.

    EDIT

    In Ant, incremental compilation can be done in two ways:

    • By default the task compares the timestamps of .java and corresponding .class files, and only tells the Java compiler to recompile source (.java) files that are newer than their corresponding target (.class) files, or that don't have a target file at all.

    • The task also takes into account dependencies between classes, which it determines by reading and analysing the dependency information embedded in the .class files. Having determined which .class files are out of date, the task deletes them so a following task will recompile them. However, this is not entirely fool-proof. For example, extensive changes to the source code can lead to the task may be analysing stale dependencies. Also certain kinds of dependency (e.g. on static constants) are not apparent in the .class file format.

      To understand why Ant is not fool-proof, read the "Limitations" section of the documentation.

提交回复
热议问题