Russell Zornes
Russell Zornes

Reputation: 706

How to change code settings in eclipse

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?

Upvotes: 2

Views: 210

Answers (2)

Dean J
Dean J

Reputation: 40288

java -DsomeFlag=true <class>

and

String flag = System.getProperty("someFlag");

Upvotes: 0

Kathy Van Stone
Kathy Van Stone

Reputation: 26271

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.

Upvotes: 3

Related Questions