How to provide preprocessor directives in Java
Java doesn't have a preprocessor, yet that doesn't mean that you can't run Java code through cpp
- though it would not be supported by any tools, AFAIK.
Use Dependency Injection/Inversion of Control. Depending on your actual needs, you might be able to get away with something as simple as property file/environment variables to control things.
You might be able to use static defines around some types of initialization/code.
Java doesn't have a preprocessor - so the simple answer is that you can't.
This sort of thing is normally handled in Java using Dependency Injection - which is both more powerful and more flexible.
http://www.vogella.com/articles/DependencyInjection/article.html