passing precompile directives to javac?
I am writing a desktop and j2开发者_开发技巧me application. I have debug statements in program. Currently to avoid those getting compiled i use as following. We are doing this to reduce size of jar. (Specifically for mobile)
ConstantFile.java
Boolean ConstantFile.DebugEnabled = false;
if(ConstantFile.DebugEnabled) {
log.debug("msg");
}
But this is sort of hard coding. Is there an alternative like C where we have pre-compiled directives. Can Annotation help here ? Or something else i should look for ?
No, there is no precompile in Java, but instead of using the constants file like you are currently using, try Log4j or some other logging package that supports an isDebugEnabled() operation. This will avoid the hardcoding in favor of a config file or VM argument.
Annotations could work, or you could look at AOP. AOP would allow you to automatically insert code into your methods at specific points. Either way should get you what you want.
I got exact answer i wanted. Preprocessor. Similar to hatchetman82 suggested, There is wtkpreprocess task available. And its specifically developed for mobile. (Though it can be used for other java part also.) And it works perfectly. It comments out line so byte code remains lighter.
精彩评论