public class PropertiesFacade
{
public PropertiesFacade()
{
}
public void loadProperties(String fileName)
{
if(properties == null)
try
{
String localFilePath = “resources/config/”;
String jarFilePath = “/config/”;
URL url = getClass().getResource(jarFilePath + fileName);
InputStream fileIn;
if(url == null)
fileIn = new FileInputStream(localFilePath + fileName);
else
if(url.getFile().toString().indexOf(“!”) != -1)
{
JarURLConnection jarConn = (JarURLConnection)url.openConnection();
fileIn = jarConn.getInputStream();
} else
{
fileIn = new FileInputStream(url.getPath());
}
properties = new Properties();
properties.load(fileIn);
fileIn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public Properties getProperties()
{
return properties;
}
public String getProperty(String name)
{
if(properties.getProperty(name) != null)
return properties.getProperty(name);
else
return “null”;
}
private Properties properties;
}
getProperties()나 getProperty(name)을 이용하여 설정된 프로퍼티를 가져올수 있다.
A class extends PropertiesFacade 처럼 상속하여 추가기능으로 사용하도록 만들었다..
String localFilePath = “resources/config/”;
String jarFilePath = “/config/”;
의 path를 적절히 바꾸어 사용하면 된다.