aspose file tools*
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
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problem with constants" Watch "Problem with constants" New topic
Author

Problem with constants

Mike Rane
Greenhorn

Joined: Jul 27, 2005
Posts: 13
Hello,

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
Marshal

Joined: Mar 22, 2005
Posts: 42612
    
  65
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.


Ping & DNS - my free Android networking tools app
Mike Rane
Greenhorn

Joined: Jul 27, 2005
Posts: 13
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with constants