Pass Variable to Java Method from an Ant Target
Posted
by user200317
on Stack Overflow
See other posts from Stack Overflow
or by user200317
Published on 2010-05-24T20:28:11Z
Indexed on
2010/05/24
20:31 UTC
Read the original article
Hit count: 334
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.
© Stack Overflow or respective owner