I'm using java-comment-preprocessor. It is very easy and convenient and provides also integration for Maven, Ant and Gradle. It is using Java comments and a preprocessor is used generating the actual code based on the preprocessor flags, e.g.:
//#if simulator
private final static int FOO = 2;
//#else
private final static int FOO = 1;
//#endif
Maven integration:
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>jcp</artifactId>
<version>7.0.5</version>
<executions>
<execution>
<id>preprocessSources</id>
<phase>process-sources</phase>
<goals>
<goal>preprocess</goal>
</goals>
<configuration>
<vars>
<simulator>${simulator}</simulator>
</vars>
</configuration>
</execution>
</executions>
</plugin>