【发布时间】:2014-10-06 22:24:31
【问题描述】:
我编写了一个加载外部属性以在我的程序中使用的类,它是根据以下链接建模的:Load Properties File in Singleton Class。我已在此处 (FileNotFoundException with properties file) 和此处 (Java Properties File not loading) 阅读了有关如何加载外部属性文件的信息,但是我继续收到 FileNotFoundException。我的属性文件是外部的,与我的可执行 jar 位于同一目录中。
公共类 ExternalProperties 扩展属性{
private static ExternalProperties instance = null;
private Properties properties;
private static String location;
protected ExternalProperties() throws IOException {
properties = new Properties();
properties.load(getClass().getResourceAsStream("test.properties"));
}
public static ExternalProperties getInstance(){
if(instance == null){
try{
instance = new ExternalProperties();
} catch (IOException e) {
e.printStackTrace();
}
}
return instance;
}
public static void setLocation(String path){
location = path;
}
}
我通过命令行传递属性文件的位置如:
java -jar chef-deploy-tests-0.0.0009-SNAPSHOT-jar-with-dependencies.jar test.properties
关于我做错了什么有什么建议吗?
【问题讨论】:
标签: java properties