这个方法可以防止jar运行时找不到配置文件
1、创建一个文件夹resources,与src同级,并将这个文件加到build path中。这样resources就是class根目录了
2、程序获取配置文件
public class LoadLog4J {
static Logger log = Logger.getLogger(LoadLog4J.class);
public static void load() throws IOException{
InputStream is = LoadLog4J.class.getClassLoader().getResourceAsStream("log4j.properties");
Properties pro = new Properties();
pro.load(is);
if(is != null){
is.close();
}
PropertyConfigurator.configure(pro);
log.info("加载log4j配置成功");
}
}