tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wendy Smoak <>
Subject Re: reading file in ServletContextListener
Date Sun, 27 Nov 2005 22:46:54 GMT
On 11/27/05, Werner van Mook <> wrote:
> To make it more clear of what I try to do here is the complete method
> in which I try to read a file.
>      private void list() throws Exception {
>          XMLReader parser = XMLReaderFactory.createXMLReader(
>                  "org.apache.xerces.parsers.SAXParser");
>          parser.setContentHandler(new PeopleHandler());
>          parser.parse("/WEB-INF/friends.xml");
>      }
> This parse method want an InputSource. Sorry Wendy it didn't work.
> I tried filling in a fully qualified URI. It completely stops tomcat
> from starting.
> The URI is to a file in the webapp which is trying to start.

If you're using getResourceAsStream to get an InputSource, then I
think the file would have to be on the classpath, so not in WEB-INF
directly, but in WEB-INF/classes (or in a .jar file in WEB-INF/lib.)

I have a .properties file in WEB-INF/classes that gets read from a
ServletContextListener by way of a Factory that does this:
         Properties props = new Properties();
         ClassLoader cl = UniSessionFactory.class.getClassLoader();
         InputStream input = cl.getResourceAsStream( propsFileName );
         props.load( input );

So I'm fairly sure that by the time your ServletContextListener is
called, the file should be in place and available.

Please post both the code you're using and the resulting error message
if you still need help.  Just telling us Tomcat doesn't start is not
enough information.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message