Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Compiling differently for debug and release

807607Jan 1 2007 — edited Jan 2 2007
I want to produce slightly different .class files for my debug and release compilations. For debug, methods like toString() should return rich information which should not be present in the release version. In fact, I want most of my debug specific code to not be included in the final release to keep ti's file size down.

I realise I can do this by creating something like
public interface MyGlobals {
    static final boolean DEBUG = false;
}
and implementing this on any class that needs to do debug specific work. However, I'm in a bit of a chicken and egg scenerio. This file needs to exist during development time so that every class that needs it can implement it - however, this would prevent me from dynamically changing it based on whether I'm doing a debug or release build. On the other hand, if the file is generated automatically at compile time, all the classes that need to refer to it will need to refer to a non-existant source file, which will cause problems in my NetBeans IDE.

Is there a way around this? It would be nice if there was some sort of a configuration file you could specify to to alter how the code is generated. Something similar to C++ #ifdef.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 30 2007
Added on Jan 1 2007
9 comments
273 views