'Paul Z. Wu' zwu_net-/E1597aS9LQAvxtiuMwx3w@public.gmane.org [seajug]
2014-05-30 17:09:21 UTC
I have a class below for a lib (jar) I'm creating. This library will be used in both a standalone program and a web app.
Look at the italic line. It is fine when deployed in the web app, but it will get a java.lang.ExceptionInInitializerError when use it for the standalone program. If I replace the line with
config.load(Class.class.getResourceAsStream("/config.properties"));
The reversed thing happens: the web app will get java.lang.ExceptionInInitializerError, but the standalone will be fine. How can I load the resource that works for the both cases?
public class UsidBits {
final static Properties config = new Properties();
static {
try {
config.load(UsidBits.class.getClassLoader().getResourceAsStream("/config.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
......
}
Paul Z. Wu
http://www.elookinto.com
Look at the italic line. It is fine when deployed in the web app, but it will get a java.lang.ExceptionInInitializerError when use it for the standalone program. If I replace the line with
config.load(Class.class.getResourceAsStream("/config.properties"));
The reversed thing happens: the web app will get java.lang.ExceptionInInitializerError, but the standalone will be fine. How can I load the resource that works for the both cases?
public class UsidBits {
final static Properties config = new Properties();
static {
try {
config.load(UsidBits.class.getClassLoader().getResourceAsStream("/config.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
......
}
Paul Z. Wu
http://www.elookinto.com