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 Problem with constants Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problem with constants" Watch "Problem with constants" New topic

Problem with constants

Mike Rane

Joined: Jul 27, 2005
Posts: 13

I am using ant to build a program. When I rebuild after having changed some constants in my program, the program still uses the old values of the constants. If I do a clean and rebuild the new values are used. How can I set things up so that I don't need to do a clean before I rebuild?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The problem is that if you have "final" constants, their value gets compiled into the classes that use them directly - the resulting class file does not have a reference to the class they came from. So if that final value changes in the source code, all classes that use it need to be recompiled in order to pick up the new value.
Either force a clean compile whenever you change a final constant, or don't make the constants final. A really good build tool could detect this situation automatically and recompile as necessary, but I'm not aware of one that does this.
Mike Rane

Joined: Jul 27, 2005
Posts: 13
I agree. Here's the link:
subject: Problem with constants
It's not a secret anymore!