File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Compilation error while using Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Compilation error while using Ant" Watch "Compilation error while using Ant" New topic

Compilation error while using Ant

Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
I am building around 5K files using Ant.At times , when i update(add some constants) a file having constants (static final variable) & start building , the file with constants is not getting compiled.
And i get an error like ... var ABC (added constant) is undefined.
What could be the issue?
Thanks & Regards
Peter Johnson

Joined: May 14, 2008
Posts: 5852

Ant will compile only .java files that have changed (actually, only the .java files whose timestamps are more recent that the timestamps on the corresponding .class files) With constants, this can be very tricky. If you change the file containing the constant, it will be recompiled but the files that use the constant are not recompiled. At least not unless you specify such dependencies (I think there is a way to do this in Ant, I haven't used it). The workaround I use is to always call the 'clean' task first - then I'm sure to have everything compiled properly.

In you case, it might be that the .java file referencing the new constant is being compiled first and the compiler is still referencing the old .class file (that is just a guess). But calling 'clean' first should solve this also.

JBoss In Action
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Thanks a lot.Clean build is solving the problem.
I agree. Here's the link:
subject: Compilation error while using Ant
It's not a secret anymore!