开发者

passing precompile directives to javac?

开发者 https://www.devze.com 2022-12-21 16:20 出处:网络
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. (

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号