You should use getResourceAsStream. For example one of my MBeans reads some configuration information from META-INF/keys.xml located in the JAR the MBean class is in.
InputStream publicKeyStream = this.getClass().getClassLoader().getResourceAsStream("META-INF/keys.xml");
Sometimes, you can get an incomplete read of the file using the standard InputStream and what you read into the buffer is less than what is available in the stream - .available() > .read(buffer, 0, .available()). If this happens, wrap it in a BufferedInputStream.
Thanks. I was expecting some sort of JNDI answer, but I guess the root directory is based on the ClassLoader, huh.
My server has gone to the shop for a week, so I can't test it until it returns. I'll write again if it doesn't work.
I suppose you could do it via JNDI but normally, you'd reserve that for things that global components need to share.
One other thing: servlets have a ServletContext.getResourceAsStream() method as well, which reads from the servlet's context, and prevents you from going to some other place outside your context. So if you want to get something from the WAR WEB-INF directory, you have to append a '/'.
e.g. stream = context.getResourceAsStream("/WEB-INF/mykeys.xml");