【发布时间】:2011-02-23 09:54:47
【问题描述】:
目前我有一个 .properties 文件来存储与框架相关的设置。 示例:
default.auth.url=http://someserver-at008:8080/
default.screenshots=false
default.dumpHTML=false
我已经编写了一个类来提取这些值,这是该类的方法。
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;
}
在整个应用程序中,我使用如下方法来精确确定所需的属性:
public String getBrowserDefaultCommand() {
String bcmd = SeleniumDefaultProperties.getResourceAsStream("default.browser.command");
if(bcmd.equals(""))
handleMissingConfigProperties(SeleniumDefaultProperties.getResourceAsStream("default.browser.command"));
return bcmd;
}
但我还没有决定对此进行更改并使用 Ant 并传递参数而不是从 .properties 文件中使用它。
我想知道如何使用 Ant 将值传递给 Java 方法。这些类都没有主要方法,也没有任何主要方法。因此,我无法使用 java 系统属性。
【问题讨论】:
标签: java ant build properties