我的以下代码不会产生预期的输出:
public static void main(String[] args) throws MalformedURLException {
Configuration.addDefaultResource("/home/some_user/conf.xml");
Configuration conf = new Configuration();
System.out.println(conf);
System.out.println(conf.get("color"));
assertThat(conf.get("color"), is("yellow"));
}
该属性color
在 conf.xml 文件中设置如下:
<property>
<name>color</name>
<value>yellow</value>
<description>Color</description>
</property>
看起来文件conf.xml
没有被合并到默认配置中。
的文档Configuration.addDefaultResource(String param)
说参数应该在类路径中。当我已经为程序提供完整的绝对路径时,我不明白如何将文件添加到类路径中。