目前,我有一个.properties文件来存储与框架相关的设置。 实施例:从Ant目标将变量传递给Java方法
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系统属性。
我发现这在提交问题之前进行Google搜索期间的网站,但它不起作用。 – 2010-05-24 21:02:04