Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can standard Sun javac do incremental compiling?

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 compiling. But I'm still a bit unsure about this since I can't find any authoritative documentation about both - eclispse's and sun's - compilers "incremental feature". 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?

Edit: I'm not using Eclipse autobuild feature but instead I'm setting

-Dbuild.compiler=org.eclipse.jdt.core.JDTCompilerAdapter 

for my ant builds.

like image 683
calavera.info Avatar asked Apr 07 '10 07:04

calavera.info


People also ask

How does incremental compilation work?

In imperative programming and software development, incremental compilation takes only the changes of a known set of source files and updates any corresponding output files (in the compiler's target language, often bytecode) that may already exist from previous compilations.

Is javac a cross compiler?

By default, classes are compiled against the bootstrap and extension classes of the platform that javac shipped with. But javac also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation.

What is ECJ compiler?

ecj is the batch compiler from Eclipse and is available as ecj. jar. Since 3.3, this jar also contains the support for jsr199 (Compiler API) and the support for jsr269 (Annotation processing). In order to use the annotations processing support, a 1.6 VM is required.

Does Eclipse have its own compiler?

The Eclipse IDE comes bundled with its own Java compiler called Eclipse Compiler for Java (ECJ). This is an incremental compiler that can compile only the modified files instead of having to always compile the entire application.


2 Answers

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 <javac> 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 <depend> 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 <depend> task deletes them so a following <javac> task will recompile them. However, this is not entirely fool-proof. For example, extensive changes to the source code can lead to the <depend> 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 <depend> is not fool-proof, read the "Limitations" section of the documentation.

like image 152
Stephen C Avatar answered Sep 24 '22 00:09

Stephen C


Javac only compiles source files that are either named on the command line or are dependencies and are out of date. Eclipse may have a finer-grained way of deciding what that means.

like image 24
user207421 Avatar answered Sep 25 '22 00:09

user207421