views:

32

answers:

1

At the moment I have a .properties file to store settings related to the framework. Example: default.auth.url=http://someserver-at008:8080/ default.screenshots=false default.dumpHTML=false

And I have written a class to extract those values and here is the method of that class.

    public static String getResourceAsStream(String defaultProp) {
    String defaultPropValue = null;
    //String keys = null;
    try {
        InputStream inputStream = SeleniumDefaultProperties.class.getClassLoader().getResourceAsStream(PROP_FILE);
        Properties properties = new Properties();
        //load the input stream using properties.
        properties.load(inputStream);
        defaultPropValue = properties.getProperty(defaultProp);

    }catch (IOException e) {
        log.error("Something wrong with .properties file, check the location.", e);
    }
    return defaultPropValue;
}

Throughout the application I use method like follows to just exact property needed,

    public String getBrowserDefaultCommand() {
    String bcmd = SeleniumDefaultProperties.getResourceAsStream("default.browser.command");
    if(bcmd.equals(""))
        handleMissingConfigProperties(SeleniumDefaultProperties.getResourceAsStream("default.browser.command"));
    return bcmd;
}

But I have not decided do a change to this and use ant and pass a parameter instead of using it from .properties file.

I was wondering how could I pass a value to a Java Method using ANT. Non of these classes have Main methods and will not have any main. Due to this I was unable to use it as a java system properties.

Thanks in advance.

+1  A: 

I think you will want to pass property values on the command line using the -Dpropname=propvalue syntax when you invoke java. See here.

Dave
I found this site during a Google search prior to submitting the question but it didn't work.