I have entered couple of same line of code in my different java files. I want to make a property file which would allow me to either turn on or off (comment/uncomment those lines of code) that code. But i couldn't figure out how can I achieve that. Any guidelines or tutorial will be greatly appreciated.
Asked
Active
Viewed 84 times
-5
-
Your description is very vague. Probably best to show some of the code... – jlordo May 28 '13 at 00:31
-
Take a look at. http://stackoverflow.com/questions/1318347/how-to-use-java-property-files – greedybuddha May 28 '13 at 00:31
-
Use `if(getRunTheCodeOrNot()) { ... }` – May 28 '13 at 00:38
1 Answers
2
Java does not have a conditional compilation preprocessor like C/C++, so technically what you ask (commenting/uncommenting) is not possible with the standard tooling.
The Java assertion mechanism could be used if it is OK to turn them all on or off en masse.
Otherwise, you are probably left with taking on a little overhead to handle it at runtime. This probably looks like using an instance of java.util.Properties to read your file, storing the results in appropriately accessible objects, and using if/then to activate/deactivate the code.

Arthur Dent
- 785
- 3
- 7