Why does javac not check timestamps?

L

Lars Andersson

Dependency-checking works fine with javac (e.g. you only need to
specify x.java as the argument and y.java, if referenced by x.java, is
automatically compiled).

However, when y.java is updated and there is already a file called
y.class, y.java is not recompiled.

Why is that? Wouldn't it be trivial to add that feature to javac and
make advanced build tools unneccessary?
 
V

visionset

Lars Andersson said:
Dependency-checking works fine with javac (e.g. you only need to
specify x.java as the argument and y.java, if referenced by x.java, is
automatically compiled).

However, when y.java is updated and there is already a file called
y.class, y.java is not recompiled.

Why is that? Wouldn't it be trivial to add that feature to javac and
make advanced build tools unneccessary?

What about all the other none java sourcecode resources that change during
development?
I can't see me ever using anything other than Ant or the likes for anything
more than trivial. You should check out Ant, I don't know anyone who isn't
an instant convert. You get so much with such little complexity.
 
E

Esmond Pitt

Lars said:
Dependency-checking works fine with javac (e.g. you only need to
specify x.java as the argument and y.java, if referenced by x.java, is
automatically compiled).

However, when y.java is updated and there is already a file called
y.class, y.java is not recompiled.

Why is that?

What makes you think it doesn't?

From the documentation for 'javac': javac determines whether the class
file is out of date. If the class file is out of date, javac recompiles
the source file and uses the updated class file. Otherwise, javac just
uses the class file.
 
I

ivan danicic

visionset said:
Hello, I have been caught out by this. If x is the main class and y uses x
but not vice versa, directly or indirectly, then updating y and compiling x
does no good. In complicated cases it's not easy to determine what will
happen.
Ivan
 
E

Esmond Pitt

That's not inconsistent with what I said.

Also from Sun:

'javac determines whether the class file is out of date. If the class
file is out of date, javac recompiles the source file and uses the
updated class file. Otherwise, javac just uses the class file.'

That specifically counters your statement 'y.java, if referenced by
x.java, is automatically compiled). However, when y.java is updated and
there is already a file called y.class, y.java is not recompiled.'

The difference might appear subtle but it is there. What javac doesn't
do is chase other classes which are dependent on B (or Y) if B/Y is
recompiled by the rule above. It only explores the dependencies of the
class trees starting at the classes passed in the command line.

[Lars, just repeating this here for the benefit of the NG.]
 
M

Mike Schilling

Lars said:
"If A uses B and B is changed, A.java would not be recompiled unless
explicitly specified. On the other hand, each explicitly passed source
is always recompiled, whether this is really required or not."

That's a different statement, though: it describes how dependencies between
*different* classes are handled. It remains true that if javac needs to
process B and notices that B.class is older than B.java, it will compile B.
But if:

* neither A nor B is specicifed on the command line
* the compiler processes class A
* A uses B
* B.java is newer than B.class
* A.class is newer than B.java

then B will be recompiled, but A will not.

The result, whether using Ant to call javac or javac directly is the
following:

o Most of the time, the lazy compilation done by javac works fine.
o On occasion, it doesn't, and the simplest thing to do is delete all of the
class files and recompile the world.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top