Sorry if the question title is confusing. Let me explain further.
I am building a Java project with Eclipse. In my Java product I have conditionals that determine what code is included in the product and relies on static final constants for dead stripping.
class BuildFlags
{
public static final boolean SOME_FLAG = true; // Need to set this programmatically
}
class SomeOtherClass
{
public void someMethod()
{
if (BuildFlags.SOME_FLAG)
{
// flag specific code
}
}
}
My question is how can I change BuildFlags.SOME_FLAG (above) so that I can run a special build without changing the source? Is there some way I can pass flags to the jvm (from eclipse) which I can then access to set this flag programatically?
You do this by setting a system property value (see the docs on java) and then getting it from
System.getProperty(). System properties can be set in Eclipse by editing the run configuration.Note that properties are set as strings — you will have to convert it to a boolean.