How to read a file from the WAR or webapp? If I have a configuration file, say an XML file, stored inside the WAR, how do I open it from a servlet?
Created May 14, 2012
Alessandro A. Garbagnati The WAR file is automatically opened by the servlet container during the startup... at least this is what the servlet specs are saying (and it is happening with both Resin and Tomcat). Once you reach the servlet just use ServletContext.getRealPath() to get the file.
For example if the file is in a 'template' dir under the root of the context, use
getRealPath("/template/file.xml");