在WebSphere环境中,因为工程是打成war包传上去的,和tomcat不同,无法获取配置文件路径,路径不对当然获取不到配置文件信息。下面是一种变通的方法:
//注:将配置文件和类放在同一目录下
public ArrayList getLogProperties(){
try
{
Properties prop=new Properties();
prop.load(config.class.getResourceAsStream("xxx.properties"));
Enumeration en = prop.propertyNames();
while(en.hasMoreElements())
{
String key = (String)en.nextElement();
String value = prop.getProperty(key);
if(key!=null && value!=null)
{
HashMap map = new HashMap();
map.put("name", key.toUpperCase());
map.put("value",value);
this.config_cont.add(map);
}
}
}
catch (Exception e)
{
throw new RuntimeException("[init]读取配置文件出错!"+config_cont);
}
return config_cont;
}