【发布时间】:2013-05-04 16:11:18
【问题描述】:
我有一个属性文件config.properties,其中存储了一个类加载以读取文件的路径。
属性加载如下:
public class PropertyConfig {
private static final Properties properties = new Properties();
static {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
}
}
public static String getSetting(String key) {
return properties.getProperty(key);
}
}
而相关类中的调用是这样的:
private static File savedGamesFolder = new File(PropertyConfig.getSetting("folder_for_saved_games"));
出于测试目的,我希望能够更改测试目录的路径,或更改 jUnit-TestCase 中的整个属性文件。如何做到这一点?
如果有帮助,我正在使用 Maven。
【问题讨论】:
-
如果您将
config.properties放置在src/main/resources,它将能够将新的放置在src/test/resources。
标签: maven properties overriding